RQ2: Artificially Attritioned Datasets

Data cleaning

Load Results

The script 2_rq2_1_run_bootstrapping.R runs the bootstrap analyses and saves the results - which are then cleaned and presented below.

Code
source("0_load_data.R")
rm(rq1y, rq1y_labels, rq1y_labels_clean)

# Load new bootstrap results
boot_results           = readRDS(file = file.path("results", "2_boot_results.Rds"))

number_timepoints = length(rq1y_twin1)
number_bootstraps = length(boot_results)/number_timepoints

# ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# Post-processing of results ---------------------------------------------------
# ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

joblist = expand.grid(
  b = 1:number_bootstraps,
  i = 1:number_timepoints
  )

### Extract data from boot_results ---------------------------------------------

md_df = do.call(rbind, lapply(seq_along(boot_results), function(j) {
  result_vec = boot_results[[j]]$md[[1]]
  data.frame(
    .dataset = joblist[j, "i"],
    .boot    = joblist[j, "b"],
    t(setNames(result_vec, rq2y))
  )
}))

smd_df = do.call(rbind, lapply(seq_along(boot_results), function(j) {
  result_vec = boot_results[[j]]$smd[[1]]
  data.frame(
    .dataset = joblist[j, "i"],
    .boot    = joblist[j, "b"],
    t(setNames(result_vec, rq2y))
  )
}))

var_df = do.call(rbind, lapply(seq_along(boot_results), function(j) {
  result_vec = boot_results[[j]]$var[[1]]
  data.frame(
    .dataset = joblist[j, "i"],
    .boot    = joblist[j, "b"],
    t(setNames(result_vec, rq2y))
  )
}))

cor_df = do.call(rbind, lapply(seq_along(boot_results), function(j) {
  result_vec = boot_results[[j]]$cor_resid[[1]]
  data.frame(
    .dataset = joblist[j, "i"],
    .boot    = joblist[j, "b"],
    t(result_vec)
  )
}))

srmr_df = do.call(rbind, lapply(seq_along(boot_results), function(j) {
  data.frame(
    .dataset = joblist[j, "i"],
    .boot    = joblist[j, "b"],
    srmr     = boot_results[[j]]$srmr[[1]]
  )
}))

ace_df = do.call(rbind, lapply(seq_along(boot_results), function(j) {
  ace_est  = boot_results[[j]]$ace[[1]]$ace_estimates
  ace_diff = boot_results[[j]]$ace[[1]]$ace_differences
  result_df = rbind(ace_est, ace_diff)
  result_df$.dataset = joblist[j, "i"]
  result_df$.boot    = joblist[j, "b"]
  return(result_df)
}))

rownames(md_df)   = NULL
rownames(smd_df)  = NULL
rownames(var_df)  = NULL
rownames(cor_df)  = NULL
rownames(srmr_df) = NULL

bootstrap_iter = list(md = md_df, smd = smd_df, var = var_df, cor_resid = cor_df, srmr = srmr_df)

### Calculate p-values and confidence intervals per dataset --------------------

bootstrap_summary_df = lapply(names(bootstrap_iter)[1:3], function(stat_name) {
  df = bootstrap_iter[[stat_name]]
  
  dataset = df %>%
    pivot_longer(
      cols = !starts_with(".")
    ) %>%
    group_by(.dataset, name) %>%
    summarise(
      .mean_qi_pd(value),
      .groups = "drop"
    ) %>%
    mutate(
      dataset       = rq1y_twin_labels_clean_extrashort[.dataset],
      variable      = rq2y_labels_short[match(name, rq2y)],
      stat          = stat_name
    ) %>%
    select(-.dataset, -name) %>%                                                                                                                                                           
    relocate(dataset, variable, stat) 
})

bootstrap_summary_df = do.call(rbind, bootstrap_summary_df)
rownames(bootstrap_summary_df) = NULL

### Calculate bootstrap summaries for ACE separately ---------------------------

bootstrap_summary_df_ace = ace_df %>%
  filter(name != "amohqualn1") %>%
  mutate(
    group = recode(group,
      "df1"  = "Attritioned",
      "df2"  = "Original",
      "diff" = "Difference"
    ),
    dataset       = rq1y_twin1[.dataset],
    dataset_label = rq1y_twin_labels_clean_extrashort[.dataset]
  ) %>%
  group_by(par, name, sex, group, dataset, dataset_label) %>%
  summarise(
    .mean_qi_pd(value),
    .groups = "drop"
  ) 


variable_comparisons_df = bootstrap_summary_df %>%
  group_by(dataset, stat) %>%
  mutate(
    pval_adj = stats::p.adjust(pval, method = "holm")
  )

Create Attritioned Datasets

To remove participants, I’ve set the rows to NA rather than remove the rows, so all the datasets have the same length. This preserves the paired twin structure needed for bootstrapping and ACE analyses.

Code
attritioned_datasets = list()

for (i in seq_along(rq1y_twin1)){
  
  filter = as.numeric(df[[rq1y_twin1[i]]])==0 # 1 = present (Y), 2 = not-present (N)
  
  attritioned_datasets[[i]] = df %>% 
    select(all_of(rq2y))
  
  attritioned_datasets[[i]][filter,] = NA
  
}

original_dataset = df %>%
  select(all_of(rq2y))

Comparison of Means, Standardized Mean Differences, and Variances

Create GT Results table

Code
variable_comparisons_df %>% 
  select(-starts_with("."),-pd, -pval) %>%
  pivot_wider(
    names_from = "stat",
    values_from = c("y","ymin","ymax","pval_adj"),
    id_cols = c("variable", "dataset")
  ) %>%
  dplyr::rename( Outcome = "variable") %>%
  gt(groupname_col = "dataset") %>%
  tab_options(
    table.width = px(800)
    # table.border.top.style = "none",
    # table.border.bottom.style = "none",
    # column_labels.border.bottom.style = "solid",
    # column_labels.border.bottom.width = px(1),
    # column_labels.border.bottom.color = "black",
    # table_body.border.bottom.style = "none",
    # table_body.vlines.style = "none",
    # row_group.border.bottom.style = "none"
  ) %>%
  
  # Create column spanners (nested headers)
  tab_spanner(
    label = "Mean Difference",
    columns = c(y_md, ymin_md, ymax_md, pval_adj_md)
  ) %>%
  tab_spanner(
    label = "Standardized Mean Difference", 
    columns = c(y_smd, ymin_smd, ymax_smd, pval_adj_smd)
  ) %>%
  tab_spanner(
    label = "Variance % Change",
    columns = c(y_var, ymin_var, ymax_var, pval_adj_var)
  ) %>%
  
  # Rename columns under each spanner
  cols_label(
    y_md = "Est", ymin_md = "LB", ymax_md = "UB", pval_adj_md = "p",
    y_smd = "Est", ymin_smd = "LB", ymax_smd = "UB", pval_adj_smd = "p", 
    y_var = "Est", ymin_var = "LB", ymax_var = "UB", pval_adj_var = "p"
  ) %>%
  
  # Format numbers
  fmt(
    columns = !contains("var") & !contains("Outcome"),
    fns = function(x) {gbtoolbox::apa_num(x, n_decimal_places = 3)}
  ) %>% 
  fmt(
    columns = "pval_adj_var",
    fns = function(x) {gbtoolbox::apa_num(x, n_decimal_places = 3)}
  ) %>% 
  fmt_percent(
    columns = c("y_var", "ymin_var","ymax_var"),
    decimals = 2,
    drop_trailing_zeros = FALSE,
    drop_trailing_dec_mark = FALSE
  ) %>%
  # Styling - uniform font size
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_column_spanners()
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_body()
  ) %>%
  tab_style(
    style = cell_text(size = px(10), align = "center"),
    locations = cells_row_groups()
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_column_labels()
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_footnotes()
  ) %>%
  
  # Highlight significant results - positive effects (light green)
  tab_style(
    style = cell_fill(color = "#d5e8d4"),  # Light green for positive effects
    locations = cells_body(
      columns = c(y_md, ymin_md, ymax_md, pval_adj_md),
      rows = pval_adj_md < 0.05 & y_md > 0
    )
  ) %>%
  tab_style(
    style = cell_fill(color = "#d5e8d4"),  # Light green for positive effects
    locations = cells_body(
      columns = c(y_smd, ymin_smd, ymax_smd, pval_adj_smd),
      rows = pval_adj_smd < 0.05 & y_smd > 0
    )
  ) %>%
  tab_style(
    style = cell_fill(color = "#d5e8d4"),  # Light green for positive effects
    locations = cells_body(
      columns = c(y_var, ymin_var, ymax_var, pval_adj_var),
      rows = pval_adj_var < 0.05 & y_var > 0
    )
  ) %>%
  
  # Highlight significant results - negative effects (light red)
  tab_style(
    style = cell_fill(color = "#f8cecc"),  # Light red for negative effects
    locations = cells_body(
      columns = c(y_md, ymin_md, ymax_md, pval_adj_md),
      rows = pval_adj_md < 0.05 & y_md < 0
    )
  ) %>%
  tab_style(
    style = cell_fill(color = "#f8cecc"),  # Light red for negative effects
    locations = cells_body(
      columns = c(y_smd, ymin_smd, ymax_smd, pval_adj_smd),
      rows = pval_adj_smd < 0.05 & y_smd < 0
    )
  ) %>%
  tab_style(
    style = cell_fill(color = "#f8cecc"),  # Light red for negative effects
    locations = cells_body(
      columns = c(y_var, ymin_var, ymax_var, pval_adj_var),
      rows = pval_adj_var < 0.05 & y_var < 0
    )
  ) %>%
  
  # Add footnotes
  tab_footnote(
    footnote = md("<em>Note.</em> Est = Estimate, LB = Lower Bound 95% Confidence Interval, UB = Upper Bound 95% Confidence Interval. Significant (p<sub>Bonferroni-Holm</sub>) effects are highlighted in green (increases) or red (decreases)."),
    # locations = cells_column_spanners(),
    placement = "right"
  ) %>%
  tab_footnote(
    footnote = "P values are Bonferroni-Holm adjusted within each participation group",
    locations = cells_column_labels(columns = contains("pval_adj")),
    placement = "right"
  ) %>%
  tab_footnote(
    footnote = md("Standardized mean difference = (Mean<sub>original</sub> - Mean<sub>attritioned</sub>) / SD<sub>original</sub>"),
    locations = cells_column_spanners(spanners = "Standardized Mean Difference"),
    placement = "right"
  ) %>%
    tab_footnote(
    footnote = md("Percentage change = (Var<sub>attritioned</sub> - Var<sub>original</sub>) / Var<sub>original</sub>"),
    locations = cells_column_spanners(spanners = "Variance % Change"),
    placement = "right"
  ) %>%
  opt_footnote_marks(marks = c("*", "†","‡"))
Outcome
Mean Difference
Standardized Mean Difference*
Variance % Change†
Est LB UB p‡ Est LB UB p‡ Est LB UB p‡
Y4
Maternal Education .267 .240 .295 .000 .134 .120 .148 .000 5.54% 4.03% 7.07% .000
Parent-admin cognition -.018 -.032 -.004 .059 -.018 -.032 -.004 .059 −4.01% −5.81% −2.20% .000
Grammar .008 -.002 .019 .258 .011 -.003 .025 .258 −0.06% −1.16% 1.04% .910
Parent-report cognition .066 .017 .115 .047 .020 .005 .034 .047 −4.93% −7.36% −2.60% .000
Conduct problems -.050 -.070 -.031 .000 -.034 -.047 -.021 .000 −4.40% −6.49% −2.36% .000
Emotional problems -.007 -.019 .004 .258 -.008 -.022 .005 .258 −2.16% −4.29% −0.13% .139
Hyperactivity -.034 -.054 -.013 .006 -.021 -.033 -.008 .006 −1.00% −2.47% 0.45% .363
Peer problems -.024 -.037 -.012 .002 -.025 -.038 -.012 .002 −3.42% −5.39% −1.52% .001
Prosocial behavior -.036 -.067 -.006 .070 -.016 -.030 -.003 .070 1.47% −0.19% 3.09% .235
Vocabulary .352 -.027 .734 .212 .014 -.001 .029 .212 −3.01% −4.70% −1.42% .001
Y12 (web test)
Maternal Education .403 .366 .442 .000 .202 .183 .221 .000 5.20% 3.13% 7.25% .000
Parent-admin cognition -.035 -.057 -.013 .008 -.035 -.057 -.013 .008 −7.80% −10.43% −5.13% .000
Grammar .024 .007 .042 .026 .032 .009 .054 .026 −0.21% −1.98% 1.60% .824
Parent-report cognition .154 .076 .231 .001 .046 .023 .069 .001 −9.12% −12.54% −5.74% .000
Conduct problems -.064 -.093 -.034 .000 -.043 -.063 -.023 .000 −5.09% −8.18% −1.98% .009
Emotional problems .008 -.009 .025 .724 .009 -.011 .030 .724 −2.81% −5.99% 0.32% .247
Hyperactivity -.051 -.083 -.019 .011 -.031 -.050 -.011 .011 −2.23% −4.50% 0.05% .222
Peer problems -.044 -.064 -.025 .000 -.045 -.065 -.025 .000 −5.62% −8.60% −2.68% .001
Prosocial behavior -.022 -.071 .026 .724 -.010 -.032 .012 .724 1.22% −1.53% 3.89% .748
Vocabulary .619 .029 1.222 .121 .025 .001 .048 .121 −4.99% −7.55% −2.50% .000
Y12 (q'aire)
Maternal Education .395 .356 .434 .000 .198 .179 .217 .000 5.72% 3.62% 7.83% .000
Parent-admin cognition -.029 -.050 -.007 .050 -.029 -.051 -.007 .050 −5.03% −7.59% −2.46% .002
Grammar .019 .002 .036 .110 .024 .003 .046 .110 0.39% −1.28% 2.11% .719
Parent-report cognition .139 .066 .213 .000 .041 .020 .063 .000 −7.70% −11.10% −4.41% .000
Conduct problems -.076 -.105 -.047 .000 -.051 -.071 -.032 .000 −5.04% −8.04% −2.05% .006
Emotional problems .006 -.011 .023 .975 .007 -.013 .028 .975 −2.83% −5.94% 0.14% .199
Hyperactivity -.041 -.072 -.009 .050 -.025 -.043 -.006 .050 −2.30% −4.54% −0.11% .167
Peer problems -.050 -.069 -.031 .000 -.050 -.070 -.031 .000 −4.83% −7.62% −1.99% .004
Prosocial behavior -.015 -.063 .032 .975 -.007 -.028 .015 .975 1.24% −1.47% 3.87% .719
Vocabulary .512 -.061 1.090 .245 .020 -.002 .043 .245 −3.21% −5.72% −0.70% .062
Y16 (q'aire)
Maternal Education .456 .411 .500 .000 .229 .207 .251 .000 6.72% 4.39% 9.05% .000
Parent-admin cognition -.030 -.056 -.004 .124 -.030 -.056 -.004 .124 −6.60% −9.67% −3.49% .000
Grammar .012 -.009 .033 .775 .015 -.011 .042 .775 −0.17% −2.25% 1.89% .869
Parent-report cognition .110 .020 .199 .085 .033 .006 .059 .085 −5.48% −9.34% −1.52% .043
Conduct problems -.109 -.143 -.075 .000 -.074 -.097 -.051 .000 −8.66% −12.14% −5.13% .000
Emotional problems .002 -.018 .022 .858 .002 -.021 .026 .858 −3.61% −7.20% −0.06% .142
Hyperactivity -.078 -.116 -.039 .001 -.047 -.070 -.024 .001 −3.38% −6.07% −0.65% .052
Peer problems -.057 -.080 -.034 .000 -.057 -.081 -.034 .000 −4.83% −8.31% −1.28% .043
Prosocial behavior -.047 -.105 .010 .429 -.021 -.047 .005 .429 1.77% −1.43% 4.98% .582
Vocabulary .320 -.381 1.021 .775 .013 -.015 .040 .775 −4.24% −7.28% −1.27% .043
Y18
Maternal Education .391 .359 .422 .000 .196 .180 .211 .000 5.46% 3.79% 7.15% .000
Parent-admin cognition -.046 -.066 -.026 .000 -.046 -.066 -.026 .000 −3.80% −6.22% −1.37% .011
Grammar .007 -.008 .023 1.000 .009 -.011 .029 1.000 0.69% −0.86% 2.23% 1.000
Parent-report cognition .083 .015 .151 .098 .025 .004 .045 .098 −4.44% −7.56% −1.36% .022
Conduct problems -.076 -.103 -.049 .000 -.052 -.070 -.034 .000 −5.19% −7.97% −2.41% .002
Emotional problems -.003 -.019 .012 1.000 -.003 -.022 .015 1.000 −2.75% −5.64% 0.12% .246
Hyperactivity -.038 -.067 -.010 .060 -.023 -.041 -.006 .060 −0.82% −2.86% 1.17% 1.000
Peer problems -.053 -.071 -.035 .000 -.054 -.072 -.036 .000 −4.35% −7.08% −1.67% .013
Prosocial behavior -.011 -.054 .032 1.000 -.005 -.024 .015 1.000 0.48% −1.96% 2.90% 1.000
Vocabulary .297 -.236 .815 1.000 .012 -.009 .032 1.000 −3.71% −5.95% −1.47% .011
Y21
Maternal Education .453 .411 .496 .000 .227 .207 .248 .000 7.85% 5.61% 10.07% .000
Parent-admin cognition .003 -.022 .029 1.000 .003 -.022 .029 1.000 −4.63% −7.66% −1.61% .018
Grammar .048 .027 .068 .000 .061 .035 .087 .000 0.37% −1.66% 2.39% .725
Parent-report cognition .223 .138 .309 .000 .067 .041 .092 .000 −4.98% −8.83% −1.08% .076
Conduct problems -.094 -.128 -.059 .000 -.064 -.086 -.040 .000 −7.07% −10.61% −3.54% .000
Emotional problems .001 -.019 .020 1.000 .001 -.023 .024 1.000 −3.33% −6.96% 0.33% .263
Hyperactivity -.071 -.109 -.033 .000 -.043 -.066 -.020 .000 −2.51% −5.21% 0.17% .263
Peer problems -.063 -.085 -.040 .000 -.063 -.087 -.040 .000 −7.71% −11.16% −4.22% .000
Prosocial behavior .004 -.052 .060 1.000 .002 -.023 .027 1.000 2.15% −1.09% 5.41% .379
Vocabulary 1.386 .715 2.055 .000 .055 .028 .081 .000 −4.49% −7.34% −1.56% .024
Y26 (q'aire)
Maternal Education .419 .373 .463 .000 .210 .188 .232 .000 7.75% 5.41% 10.09% .000
Parent-admin cognition .020 -.006 .047 .404 .020 -.006 .047 .404 −5.19% −8.34% −2.06% .005
Grammar .061 .039 .083 .000 .078 .051 .106 .000 0.48% −1.76% 2.71% 1.000
Parent-report cognition .187 .094 .281 .000 .056 .028 .083 .000 −5.50% −9.63% −1.37% .073
Conduct problems -.073 -.111 -.036 .000 -.050 -.075 -.024 .000 −3.84% −7.75% 0.06% .268
Emotional problems .005 -.017 .027 1.000 .006 -.020 .032 1.000 −1.32% −5.47% 2.74% 1.000
Hyperactivity -.110 -.151 -.069 .000 -.066 -.092 -.042 .000 −1.66% −4.62% 1.36% .832
Peer problems -.061 -.086 -.035 .000 -.062 -.087 -.036 .000 −5.93% −9.66% −2.07% .018
Prosocial behavior .010 -.050 .070 1.000 .005 -.023 .032 1.000 2.59% −0.88% 6.10% .591
Vocabulary 1.674 .963 2.398 .000 .066 .038 .095 .000 −3.32% −6.38% −0.30% .176
Y26 (web test)
Maternal Education .551 .479 .624 .000 .276 .241 .313 .000 9.51% 5.73% 13.28% .000
Parent-admin cognition -.009 -.052 .034 1.000 -.009 -.052 .034 1.000 −8.04% −12.90% −2.93% .022
Grammar .059 .023 .094 .007 .076 .030 .122 .007 0.16% −3.43% 3.83% 1.000
Parent-report cognition .215 .065 .366 .025 .064 .019 .109 .025 −5.46% −11.89% 1.09% .563
Conduct problems -.114 -.175 -.052 .005 -.077 -.118 -.035 .005 −3.23% −9.53% 3.42% .997
Emotional problems .029 -.007 .067 .334 .035 -.008 .078 .334 1.46% −5.01% 7.97% 1.000
Hyperactivity -.122 -.191 -.054 .005 -.074 -.116 -.033 .005 −3.97% −8.91% 0.99% .563
Peer problems -.070 -.110 -.030 .002 -.071 -.112 -.030 .002 −6.21% −12.14% −0.04% .392
Prosocial behavior -.001 -.107 .098 1.000 -.001 -.048 .045 1.000 5.10% −0.78% 11.00% .563
Vocabulary 1.337 .166 2.543 .094 .053 .007 .101 .094 −4.60% −9.70% 0.55% .563
Note. Est = Estimate, LB = Lower Bound 95% Confidence Interval, UB = Upper Bound 95% Confidence Interval. Significant (pBonferroni-Holm) effects are highlighted in green (increases) or red (decreases).
* Standardized mean difference = (Meanoriginal - Meanattritioned) / SDoriginal
† Percentage change = (Varattritioned - Varoriginal) / Varoriginal
‡ P values are Bonferroni-Holm adjusted within each participation group

Create circular heatmaps for changes in means and variances

Standardised Mean Differences

Code
  # Create circular heatmap for SMD
   heatmap_data_smd = variable_comparisons_df %>%
    filter(stat == "smd") %>%
    mutate(
      outcome_labeled = dataset,
      outcome_labeled = factor(outcome_labeled, levels = rq1y_twin_labels_clean_extrashort),
      Variables_wrapped = str_wrap(variable, width = 8),
      # Set fill value to NA if not significant, otherwise keep original sign
      fill_value = case_when(
        pval_adj < 0.05 ~ y,
        TRUE ~ NA
      )
    ) %>%
    # Order variables by number of significant effects
    group_by(variable) %>%
    mutate(n_significant = sum(pval_adj < 0.05)) %>%
    ungroup() %>%
    mutate(
      Variables_wrapped = factor(Variables_wrapped,
                                levels = unique(Variables_wrapped[order(-n_significant)]))
    )

  ggplot(heatmap_data_smd, aes(x = Variables_wrapped, y = outcome_labeled)) +
    geom_tile(aes(fill = fill_value, 
                  color = ifelse(variable %in% c("Emotional problems", "Prosocial behavior"), "azure2", "black")), 
              size = 0.5) +
    scale_color_identity() +
    geom_text(
      aes(label = ifelse(pval_adj < 0.05,
                         gsub("^(-?)0\\.", "\\1.", sprintf("%.3f", y)), ""),
          size = ifelse(outcome_labeled == "Y4", 2, 3.5)
      ),
      color = "black"
    ) +
    scale_size_identity() +
    coord_polar(theta = "x", start = 0, direction = 1, clip = "off") +
    scale_fill_gradient2(
      low = "#2166ac", 
      mid = "white", 
      high = "#d73027",
      midpoint = 0,
      # limits = c(-.1, 
      #            max(heatmap_data_smd$fill_value, na.rm = TRUE)),
      na.value = "white",
      guide = "none"
    ) +
    labs(
      title = "Standardised Mean Difference",
      subtitle = expression(frac(bar(X)[attritioned] - bar(X)[original], SD[original])),
      tag = "A"
    ) +
    theme_minimal() +
    theme(
      axis.text.x = element_text(angle = 0, size = 11, colour = "black"),
      axis.text.y = element_blank(),
      axis.title = element_blank(),
      panel.grid = element_blank(),
      panel.background = element_blank(),
      plot.background = element_blank(),
      plot.title = element_text(hjust = 0.5, size = 16),
      plot.subtitle = element_text(hjust = 0.5, size = 13.5, margin = margin(b = -20)),
      plot.tag = element_text(hjust = 0, vjust = 0, size = 30, face = "bold"),
      plot.tag.position = "topleft",
      plot.margin = margin(2, 10, -33, 10)
    ) +
    {
      y_positions = seq_along(levels(heatmap_data_smd$outcome_labeled))
      labels = levels(heatmap_data_smd$outcome_labeled)

      lapply(seq_along(labels), function(i) {
        annotate("text", x = 0.5, y = y_positions[i], 
                 label = paste0(labels[i], " "), 
                 size = 3.7, 
                 hjust = 1, angle = 7)
      })
    }
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

Code
  save_plot("2_rq2_circular_heatmap_smd", width = 8, height = 8)

Variance Differences

Code
  # Create circular heatmap for variance differences
   heatmap_data_var = variable_comparisons_df %>%
    filter(stat == "var") %>%
    mutate(
      outcome_labeled = dataset,
      outcome_labeled = factor(outcome_labeled, levels = rq1y_twin_labels_clean_extrashort),
      Variables_wrapped = str_wrap(variable, width = 8),
      # Set fill value to NA if not significant, otherwise keep original sign
      fill_value = case_when(
        pval_adj < 0.05 ~ y,
        TRUE ~ NA
      )
    ) %>%
    # Order variables by number of significant effects
    group_by(variable) %>%
    mutate(n_significant = sum(pval_adj < 0.05)) %>%
    ungroup() %>%
    mutate(
      Variables_wrapped = factor(Variables_wrapped,
                                levels = unique(Variables_wrapped[order(-n_significant)]))
    )

  ggplot(heatmap_data_var, aes(x = Variables_wrapped, y = outcome_labeled)) +
    geom_tile(aes(fill = fill_value, 
                  color = ifelse(variable %in% c("Emotional problems", "Prosocial behavior", "Hyperactivity", "Grammar"), "azure2", "black")), 
              size = 0.5) +
    scale_color_identity() +
    geom_text(
      aes(label = ifelse(pval_adj < 0.05,
                         paste0(sprintf("%.1f", y * 100), "%"), ""),
          size = ifelse(outcome_labeled == "Y4", 2, 3.5)
      ),
      color = "black"
    ) +
    scale_size_identity() +
    coord_polar(theta = "x", start = 0, direction = 1, clip = "off") +
    scale_fill_gradient2(
      low = "#2166ac", 
      mid = "white", 
      high = "#d73027",
      midpoint = 0,
      limits = c(-max(abs(heatmap_data_var$fill_value), na.rm = TRUE), 
                 max(abs(heatmap_data_var$fill_value), na.rm = TRUE)),
      na.value = "white",
      guide = "none"
    ) +
    labs(
      title = "Variance Percentage Change",
      subtitle = expression(frac(Var[attritioned] - Var[original], Var[original]) %*% 100),
      tag = "B"
    ) +
    theme_minimal() +
    theme(
      axis.text.x = element_text(angle = 0, size = 11, colour = "black"),
      axis.text.y = element_blank(),
      axis.title = element_blank(),
      panel.grid = element_blank(),
      panel.background = element_blank(),
      plot.background = element_blank(),
      plot.title = element_text(hjust = 0.5, size = 16),
      plot.subtitle = element_text(hjust = 0.5, size = 13.5, margin = margin(b = -20)),
      plot.tag = element_text(hjust = 0, vjust = 0, size = 30, face = "bold"),
      plot.tag.position = "topleft",
      plot.margin = margin(2, 10, -33, 10)
    ) +
    {
      y_positions = seq_along(levels(heatmap_data_var$outcome_labeled))
      labels = levels(heatmap_data_var$outcome_labeled)

      lapply(seq_along(labels), function(i) {
        annotate("text", x = 0.5, y = y_positions[i],
                 label = paste0(labels[i], " "), size = 3.7, hjust = 1, angle = 7)
      })
    }

Code
  save_plot("2_rq2_circular_heatmap_var", width = 8, height = 8)

Plot data distributions

Code
attritioned_datasets_long = attritioned_datasets

for (i in seq_along(attritioned_datasets_long)){
  attritioned_datasets_long[[i]] = gather(as.data.frame(as.matrix(attritioned_datasets[[i]])))
  attritioned_datasets_long[[i]]$dataset = rq1y_twin1[i]
}

x = original_dataset %>%
    as.matrix() %>% as.data.frame() %>%
    gather() %>%
    mutate(dataset = "original")

attritioned_datasets_long = c(attritioned_datasets_long, list(x))

attritioned_datasets_long = do.call(rbind.data.frame,attritioned_datasets_long)

attritioned_datasets_long = attritioned_datasets_long %>%
  filter(!is.na(value)) %>%
  mutate(
    key = rq2y_labels_short[match(key, rq2y)]
  )
  

attritioned_datasets_long %>%
  mutate(dataset = factor(dataset)) %>%
  ggplot(aes(x = value, group = dataset, col = dataset)) +
  geom_density() +
  facet_wrap(~key, scales = "free")

Alternative: Frequency polygon (better for ordinal/integer data)

Only comparing a single attrition timepoint (Y26 Questionnaire).

Code
attritioned_datasets_long %>%
  filter(!(key %in% c("Parent-admin cognition","Vocabulary"))) %>% 
  filter(dataset %in% c("original", "zmhdata1")) %>%
  mutate(
    dataset = factor(dataset),
    dataset = ifelse(dataset == "original", "original", "attritioned"),
    value = as.numeric(value)
  ) %>%
  count(key, value, dataset) %>%
  group_by(key, dataset) %>%
  mutate(prop = n / sum(n)) %>%
  ggplot(aes(x = value, y = prop, col = dataset, group = dataset)) +
  geom_line(linewidth = 1) +
  geom_point(size = 2) +
  scale_color_manual(values = c("original" = "steelblue", "attritioned" = "coral")) +
  facet_wrap(~key, scales = "free") +
  labs(
    x = "Value",
    y = "Proportion",
    title = "Distribution comparison: Original vs Participants at Y26 Questionnaire"
  ) +
  theme_minimal() +
  theme(legend.position = "bottom")

Correlations

The following code creates x_var and y_var vectors that map correlation column indices (X1, X2, etc.) to variable pairs from the lower triangle of the correlation matrix.

Code
test_correlation_matrix = matrix(
  nrow = length(rq2y),
  ncol = length(rq2y)
  )

for(i in seq_along(rq2y)){
  for(j in seq_along(rq2y)){
    test_correlation_matrix[i,j] = paste(rq2y[i], rq2y[j], collapse = " ")
  }
}

x = test_correlation_matrix[lower.tri(test_correlation_matrix)]

x_var = str_extract(x, "^\\S+")
y_var = str_extract(x, "\\S+$")

rm(test_correlation_matrix,x)

Plot changes in correlations

Code
# Get original column order before pivot
cor_col_order = setdiff(names(cor_df), c(".dataset", ".boot"))

correlation_comparisons_df = cor_df %>%
  pivot_longer(
    cols = !starts_with(".")
  ) %>%
  mutate(
    name = factor(name, levels = cor_col_order)
  ) %>%
  group_by(.dataset, name) %>%
  summarise(
    .mean_qi_pd(value),
    .groups = "drop"
  ) %>%
  group_by(.dataset) %>%
  mutate(
    pval_adj = stats::p.adjust(pval, method = "holm")
  ) %>%
  ungroup() %>%
  mutate(
    x_var = x_var[match(name, cor_col_order)],
    y_var = y_var[match(name, cor_col_order)]
  ) %>% 
  arrange(.dataset, name)

correlation_comparisons = split(correlation_comparisons_df, correlation_comparisons_df$.dataset)
correlation_comparisons = lapply(correlation_comparisons, function(x) select(x, -.dataset))
names(correlation_comparisons) = rq1y_twin1[as.numeric(names(correlation_comparisons))]

library(patchwork)

plots = lapply(1:length(correlation_comparisons), function(i) {
  correlation_comparisons[[i]] %>%
    plot_lower_triangular_matrix2(
      variables = rq2y,
      labels    = rq2y_labels_short,
      title     = rq1y_twin_labels_clean_extrashort[i],
      caption   = NULL,
      p_col     = "pval_adj",
      method    = "none"
                  )
})

patchwork::wrap_plots(
  plots,
  ncol = 3) +
  plot_annotation(
    title = "Change in Correlation",
    subtitle = expression(Cor[attritioned] ~ - ~ Cor[original]),
    theme = theme(
      plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
      plot.subtitle = element_text(hjust = 0.5, size = 16, face = "bold")
    )
  )

Code
save_plot(
  "2_rq2_2_correlations", width = 18, height = 18)

📊 View Full Resolution Correlation Plots (PNG)

Correlations results table

Below is a results table for the change in correlations.

Code
cor_table = bind_rows(correlation_comparisons, .id = "timepoint") %>%
  mutate(
    dataset = rq1y_twin_labels_clean_extrashort[match(timepoint, rq1y_twin1)],
    x_var_label = rq2y_labels_short[match(x_var, rq2y)],
    y_var_label = rq2y_labels_short[match(y_var, rq2y)],
    pair = paste(x_var_label, "×", y_var_label)
  ) %>%
  select(dataset, pair, y, ymin, ymax, pval, pval_adj) %>%
  filter(!is.na(dataset)) %>%
  gt(groupname_col = "dataset") %>%
  # tab_options(
  #   table.width = px(800)
  # ) %>%

  # Rename columns
  cols_label(
    pair = "Variable Pair",
    y = "Est",
    ymin = "LB",
    ymax = "UB",
    pval = md("p<sub>unadj</sub>"),
    pval_adj = md("p<sub>adj</sub>")
  ) %>%

  # Create column spanner
  tab_spanner(
    label = md("Correlation difference = Cor<sub>attritioned</sub> - Cor<sub>original</sub>"),
    columns = c(y, ymin, ymax, pval, pval_adj)
  ) %>%

  # Format numbers
  fmt(
    columns = c(y, ymin, ymax),
    fns = function(x) {gbtoolbox::apa_num(x, n_decimal_places = 3)}
  ) %>%
  fmt(
    columns = c(pval, pval_adj),
    fns = function(x) {gbtoolbox::apa_num(x, n_decimal_places = 3)}
  ) %>%

  # Styling - uniform font size
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_column_spanners()
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_body()
  ) %>%
  tab_style(
    style = cell_text(size = px(10), align = "center"),
    locations = cells_row_groups()
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_column_labels()
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_footnotes()
  ) %>%

  # Highlight significant results - positive effects (light green)
  tab_style(
    style = cell_fill(color = "#d5e8d4"),
    locations = cells_body(
      columns = c(pair, y, ymin, ymax, pval, pval_adj),
      rows = pval_adj < 0.05 & y > 0
    )
  ) %>%

  # Highlight significant results - negative effects (light red)
  tab_style(
    style = cell_fill(color = "#f8cecc"),
    locations = cells_body(
      columns = c(pair, y, ymin, ymax, pval, pval_adj),
      rows = pval_adj < 0.05 & y < 0
    )
  ) %>%

  # Add footnotes
  tab_footnote(
    footnote = md("<em>Note.</em> Est = Estimate, LB = Lower Bound 95% Confidence Interval, UB = Upper Bound 95% Confidence Interval. Significant (p<sub>Bonferroni-Holm</sub>) effects are highlighted in green (increases) or red (decreases)."),
    placement = "right"
  ) %>%
  tab_footnote(
    footnote = "P values are Bonferroni-Holm adjusted within each attrition timepoint",
    locations = cells_column_labels(columns = pval_adj),
    placement = "right"
  ) %>%
  opt_footnote_marks(marks = c("*", "†", "‡"))

cor_table
Variable Pair
Correlation difference = Corattritioned - Cororiginal
Est LB UB punadj padj*
Y4
Vocabulary × Maternal Education -.001 -.015 .014 .927 1.000
Grammar × Maternal Education -.001 -.014 .012 .913 1.000
Parent-admin cognition × Maternal Education .004 -.009 .017 .573 1.000
Parent-report cognition × Maternal Education .002 -.012 .015 .817 1.000
Conduct problems × Maternal Education -.002 -.015 .010 .699 1.000
Emotional problems × Maternal Education -.005 -.017 .008 .483 1.000
Hyperactivity × Maternal Education .006 -.006 .017 .332 1.000
Peer problems × Maternal Education -.002 -.015 .010 .723 1.000
Prosocial behavior × Maternal Education -.003 -.016 .010 .609 1.000
Grammar × Vocabulary .001 -.007 .009 .803 1.000
Parent-admin cognition × Vocabulary .002 -.011 .015 .799 1.000
Parent-report cognition × Vocabulary -.002 -.015 .012 .809 1.000
Conduct problems × Vocabulary -.003 -.018 .010 .636 1.000
Emotional problems × Vocabulary .005 -.009 .019 .511 1.000
Hyperactivity × Vocabulary -.001 -.014 .012 .906 1.000
Peer problems × Vocabulary -.011 -.025 .003 .133 1.000
Prosocial behavior × Vocabulary -.004 -.017 .009 .545 1.000
Parent-admin cognition × Grammar -.005 -.018 .008 .484 1.000
Parent-report cognition × Grammar -.008 -.020 .005 .245 1.000
Conduct problems × Grammar -.004 -.017 .009 .592 1.000
Emotional problems × Grammar .007 -.006 .019 .327 1.000
Hyperactivity × Grammar -.003 -.015 .010 .676 1.000
Peer problems × Grammar -.008 -.020 .005 .254 1.000
Prosocial behavior × Grammar -.001 -.014 .011 .833 1.000
Parent-report cognition × Parent-admin cognition .007 -.006 .020 .267 1.000
Conduct problems × Parent-admin cognition -.002 -.015 .011 .776 1.000
Emotional problems × Parent-admin cognition .003 -.011 .016 .692 1.000
Hyperactivity × Parent-admin cognition -.004 -.016 .009 .534 1.000
Peer problems × Parent-admin cognition -.002 -.015 .012 .792 1.000
Prosocial behavior × Parent-admin cognition -.006 -.018 .006 .333 1.000
Conduct problems × Parent-report cognition -.005 -.019 .009 .472 1.000
Emotional problems × Parent-report cognition .001 -.013 .015 .917 1.000
Hyperactivity × Parent-report cognition -.006 -.019 .007 .414 1.000
Peer problems × Parent-report cognition -.013 -.027 .001 .063 1.000
Prosocial behavior × Parent-report cognition .001 -.012 .013 .906 1.000
Emotional problems × Conduct problems -.001 -.014 .011 .831 1.000
Hyperactivity × Conduct problems .000 -.011 .011 .957 1.000
Peer problems × Conduct problems -.006 -.020 .007 .378 1.000
Prosocial behavior × Conduct problems .014 .002 .026 .024 1.000
Hyperactivity × Emotional problems -.014 -.026 -.001 .030 1.000
Peer problems × Emotional problems .001 -.012 .015 .822 1.000
Prosocial behavior × Emotional problems .006 -.006 .018 .300 1.000
Peer problems × Hyperactivity -.003 -.015 .010 .693 1.000
Prosocial behavior × Hyperactivity .002 -.009 .014 .703 1.000
Prosocial behavior × Peer problems -.004 -.016 .007 .478 1.000
Y12 (web test)
Vocabulary × Maternal Education -.009 -.032 .015 .482 1.000
Grammar × Maternal Education -.004 -.025 .019 .737 1.000
Parent-admin cognition × Maternal Education -.001 -.023 .022 .946 1.000
Parent-report cognition × Maternal Education -.022 -.045 .001 .065 1.000
Conduct problems × Maternal Education .001 -.019 .021 .943 1.000
Emotional problems × Maternal Education .002 -.019 .023 .852 1.000
Hyperactivity × Maternal Education .006 -.012 .025 .510 1.000
Peer problems × Maternal Education -.002 -.023 .018 .817 1.000
Prosocial behavior × Maternal Education -.006 -.027 .015 .587 1.000
Grammar × Vocabulary .006 -.007 .018 .364 1.000
Parent-admin cognition × Vocabulary -.010 -.030 .011 .352 1.000
Parent-report cognition × Vocabulary -.004 -.025 .018 .731 1.000
Conduct problems × Vocabulary .012 -.010 .034 .280 1.000
Emotional problems × Vocabulary .014 -.007 .035 .201 1.000
Hyperactivity × Vocabulary .007 -.014 .027 .522 1.000
Peer problems × Vocabulary -.006 -.028 .015 .558 1.000
Prosocial behavior × Vocabulary -.002 -.023 .018 .842 1.000
Parent-admin cognition × Grammar -.010 -.030 .010 .351 1.000
Parent-report cognition × Grammar -.007 -.028 .013 .465 1.000
Conduct problems × Grammar .003 -.018 .023 .790 1.000
Emotional problems × Grammar .020 -.000 .041 .053 1.000
Hyperactivity × Grammar .011 -.009 .031 .263 1.000
Peer problems × Grammar -.001 -.021 .018 .890 1.000
Prosocial behavior × Grammar -.014 -.034 .006 .176 1.000
Parent-report cognition × Parent-admin cognition -.007 -.027 .012 .479 1.000
Conduct problems × Parent-admin cognition .020 -.001 .040 .060 1.000
Emotional problems × Parent-admin cognition .013 -.007 .034 .212 1.000
Hyperactivity × Parent-admin cognition .005 -.015 .025 .622 1.000
Peer problems × Parent-admin cognition .007 -.013 .028 .494 1.000
Prosocial behavior × Parent-admin cognition -.001 -.021 .019 .936 1.000
Conduct problems × Parent-report cognition .039 .017 .062 .001 .045
Emotional problems × Parent-report cognition .020 -.001 .041 .061 1.000
Hyperactivity × Parent-report cognition .011 -.009 .032 .268 1.000
Peer problems × Parent-report cognition .010 -.012 .031 .395 1.000
Prosocial behavior × Parent-report cognition -.019 -.039 .002 .072 1.000
Emotional problems × Conduct problems -.003 -.022 .017 .799 1.000
Hyperactivity × Conduct problems -.018 -.035 -.000 .047 1.000
Peer problems × Conduct problems -.008 -.029 .013 .447 1.000
Prosocial behavior × Conduct problems .023 .004 .043 .018 .810
Hyperactivity × Emotional problems -.011 -.030 .008 .244 1.000
Peer problems × Emotional problems -.014 -.034 .006 .183 1.000
Prosocial behavior × Emotional problems .023 .003 .042 .025 1.000
Peer problems × Hyperactivity -.003 -.023 .016 .747 1.000
Prosocial behavior × Hyperactivity .004 -.015 .023 .661 1.000
Prosocial behavior × Peer problems -.007 -.025 .012 .494 1.000
Y12 (q'aire)
Vocabulary × Maternal Education -.005 -.027 .017 .669 1.000
Grammar × Maternal Education -.000 -.021 .021 .981 1.000
Parent-admin cognition × Maternal Education -.002 -.023 .020 .893 1.000
Parent-report cognition × Maternal Education -.011 -.034 .012 .344 1.000
Conduct problems × Maternal Education .003 -.017 .022 .774 1.000
Emotional problems × Maternal Education -.006 -.026 .014 .562 1.000
Hyperactivity × Maternal Education .005 -.013 .024 .582 1.000
Peer problems × Maternal Education .003 -.016 .022 .787 1.000
Prosocial behavior × Maternal Education -.006 -.026 .015 .584 1.000
Grammar × Vocabulary .010 -.002 .021 .101 1.000
Parent-admin cognition × Vocabulary -.009 -.028 .010 .373 1.000
Parent-report cognition × Vocabulary -.005 -.025 .015 .646 1.000
Conduct problems × Vocabulary .015 -.005 .036 .148 1.000
Emotional problems × Vocabulary .017 -.004 .037 .111 1.000
Hyperactivity × Vocabulary .011 -.008 .030 .278 1.000
Peer problems × Vocabulary -.009 -.029 .012 .397 1.000
Prosocial behavior × Vocabulary -.002 -.021 .018 .878 1.000
Parent-admin cognition × Grammar -.006 -.025 .014 .559 1.000
Parent-report cognition × Grammar -.003 -.022 .016 .781 1.000
Conduct problems × Grammar -.000 -.020 .019 .979 1.000
Emotional problems × Grammar .013 -.007 .032 .195 1.000
Hyperactivity × Grammar .006 -.012 .025 .528 1.000
Peer problems × Grammar -.012 -.031 .007 .216 1.000
Prosocial behavior × Grammar -.009 -.029 .011 .378 1.000
Parent-report cognition × Parent-admin cognition -.008 -.027 .011 .408 1.000
Conduct problems × Parent-admin cognition .011 -.009 .030 .275 1.000
Emotional problems × Parent-admin cognition .016 -.004 .035 .117 1.000
Hyperactivity × Parent-admin cognition .001 -.019 .021 .950 1.000
Peer problems × Parent-admin cognition .017 -.002 .037 .083 1.000
Prosocial behavior × Parent-admin cognition -.010 -.029 .009 .303 1.000
Conduct problems × Parent-report cognition .021 .000 .042 .050 1.000
Emotional problems × Parent-report cognition .012 -.008 .032 .237 1.000
Hyperactivity × Parent-report cognition -.003 -.022 .016 .723 1.000
Peer problems × Parent-report cognition .011 -.010 .031 .318 1.000
Prosocial behavior × Parent-report cognition -.022 -.041 -.002 .030 1.000
Emotional problems × Conduct problems -.008 -.026 .011 .433 1.000
Hyperactivity × Conduct problems -.016 -.033 .000 .054 1.000
Peer problems × Conduct problems -.010 -.030 .010 .355 1.000
Prosocial behavior × Conduct problems .010 -.009 .029 .300 1.000
Hyperactivity × Emotional problems -.010 -.029 .008 .273 1.000
Peer problems × Emotional problems -.006 -.025 .014 .551 1.000
Prosocial behavior × Emotional problems .029 .011 .048 .002 .090
Peer problems × Hyperactivity -.000 -.019 .018 .971 1.000
Prosocial behavior × Hyperactivity .003 -.015 .021 .735 1.000
Prosocial behavior × Peer problems -.002 -.020 .017 .825 1.000
Y16 (q'aire)
Vocabulary × Maternal Education .023 -.005 .050 .108 1.000
Grammar × Maternal Education .030 .005 .055 .022 .942
Parent-admin cognition × Maternal Education .013 -.013 .040 .333 1.000
Parent-report cognition × Maternal Education -.002 -.029 .024 .888 1.000
Conduct problems × Maternal Education .011 -.013 .035 .342 1.000
Emotional problems × Maternal Education -.010 -.035 .014 .391 1.000
Hyperactivity × Maternal Education .008 -.014 .030 .486 1.000
Peer problems × Maternal Education .006 -.017 .030 .585 1.000
Prosocial behavior × Maternal Education -.011 -.036 .015 .403 1.000
Grammar × Vocabulary .002 -.012 .016 .736 1.000
Parent-admin cognition × Vocabulary .005 -.018 .028 .639 1.000
Parent-report cognition × Vocabulary .003 -.021 .027 .787 1.000
Conduct problems × Vocabulary .007 -.019 .032 .579 1.000
Emotional problems × Vocabulary .005 -.020 .030 .697 1.000
Hyperactivity × Vocabulary .012 -.012 .036 .321 1.000
Peer problems × Vocabulary -.015 -.041 .010 .230 1.000
Prosocial behavior × Vocabulary -.005 -.029 .019 .666 1.000
Parent-admin cognition × Grammar .006 -.018 .029 .653 1.000
Parent-report cognition × Grammar -.004 -.028 .019 .706 1.000
Conduct problems × Grammar .005 -.019 .030 .659 1.000
Emotional problems × Grammar .015 -.009 .039 .219 1.000
Hyperactivity × Grammar .018 -.005 .042 .126 1.000
Peer problems × Grammar -.005 -.029 .018 .649 1.000
Prosocial behavior × Grammar -.027 -.051 -.003 .028 1.000
Parent-report cognition × Parent-admin cognition .002 -.021 .024 .875 1.000
Conduct problems × Parent-admin cognition .005 -.019 .029 .711 1.000
Emotional problems × Parent-admin cognition .007 -.017 .031 .573 1.000
Hyperactivity × Parent-admin cognition -.021 -.044 .002 .071 1.000
Peer problems × Parent-admin cognition -.008 -.032 .016 .490 1.000
Prosocial behavior × Parent-admin cognition -.017 -.041 .006 .148 1.000
Conduct problems × Parent-report cognition .034 .007 .059 .012 .540
Emotional problems × Parent-report cognition .017 -.007 .041 .158 1.000
Hyperactivity × Parent-report cognition .006 -.017 .029 .613 1.000
Peer problems × Parent-report cognition -.002 -.026 .022 .872 1.000
Prosocial behavior × Parent-report cognition -.007 -.031 .015 .528 1.000
Emotional problems × Conduct problems -.004 -.027 .019 .711 1.000
Hyperactivity × Conduct problems -.006 -.026 .014 .571 1.000
Peer problems × Conduct problems -.010 -.035 .014 .420 1.000
Prosocial behavior × Conduct problems .025 .002 .048 .036 1.000
Hyperactivity × Emotional problems -.014 -.036 .008 .215 1.000
Peer problems × Emotional problems -.014 -.038 .010 .251 1.000
Prosocial behavior × Emotional problems .027 .004 .050 .021 .942
Peer problems × Hyperactivity -.007 -.031 .016 .569 1.000
Prosocial behavior × Hyperactivity .012 -.010 .035 .271 1.000
Prosocial behavior × Peer problems -.007 -.029 .016 .542 1.000
Y18
Vocabulary × Maternal Education .021 .001 .042 .040 1.000
Grammar × Maternal Education .028 .009 .047 .003 .153
Parent-admin cognition × Maternal Education .020 .000 .039 .046 1.000
Parent-report cognition × Maternal Education -.000 -.020 .020 .990 1.000
Conduct problems × Maternal Education .004 -.014 .022 .673 1.000
Emotional problems × Maternal Education -.004 -.022 .015 .690 1.000
Hyperactivity × Maternal Education .002 -.014 .018 .845 1.000
Peer problems × Maternal Education .004 -.013 .022 .625 1.000
Prosocial behavior × Maternal Education -.007 -.026 .012 .455 1.000
Grammar × Vocabulary -.002 -.012 .008 .741 1.000
Parent-admin cognition × Vocabulary .004 -.014 .022 .639 1.000
Parent-report cognition × Vocabulary -.005 -.023 .014 .612 1.000
Conduct problems × Vocabulary .008 -.012 .027 .430 1.000
Emotional problems × Vocabulary .006 -.013 .026 .502 1.000
Hyperactivity × Vocabulary .002 -.016 .019 .843 1.000
Peer problems × Vocabulary -.008 -.027 .012 .441 1.000
Prosocial behavior × Vocabulary -.010 -.029 .008 .282 1.000
Parent-admin cognition × Grammar -.007 -.026 .011 .421 1.000
Parent-report cognition × Grammar -.011 -.029 .006 .205 1.000
Conduct problems × Grammar -.004 -.023 .014 .641 1.000
Emotional problems × Grammar .008 -.011 .026 .408 1.000
Hyperactivity × Grammar .003 -.014 .020 .753 1.000
Peer problems × Grammar .002 -.016 .020 .857 1.000
Prosocial behavior × Grammar -.019 -.036 -.001 .041 1.000
Parent-report cognition × Parent-admin cognition .005 -.012 .022 .553 1.000
Conduct problems × Parent-admin cognition -.019 -.038 -.001 .038 1.000
Emotional problems × Parent-admin cognition -.000 -.018 .018 .955 1.000
Hyperactivity × Parent-admin cognition -.010 -.028 .008 .272 1.000
Peer problems × Parent-admin cognition -.005 -.024 .013 .569 1.000
Prosocial behavior × Parent-admin cognition .003 -.014 .021 .729 1.000
Conduct problems × Parent-report cognition .017 -.003 .037 .091 1.000
Emotional problems × Parent-report cognition .002 -.017 .021 .820 1.000
Hyperactivity × Parent-report cognition .014 -.004 .031 .136 1.000
Peer problems × Parent-report cognition .012 -.006 .032 .204 1.000
Prosocial behavior × Parent-report cognition -.006 -.024 .011 .487 1.000
Emotional problems × Conduct problems .003 -.015 .021 .756 1.000
Hyperactivity × Conduct problems -.011 -.026 .004 .154 1.000
Peer problems × Conduct problems -.009 -.028 .010 .343 1.000
Prosocial behavior × Conduct problems .010 -.007 .028 .234 1.000
Hyperactivity × Emotional problems -.011 -.028 .006 .199 1.000
Peer problems × Emotional problems -.009 -.028 .009 .305 1.000
Prosocial behavior × Emotional problems .011 -.007 .028 .234 1.000
Peer problems × Hyperactivity -.008 -.026 .010 .366 1.000
Prosocial behavior × Hyperactivity .003 -.013 .019 .736 1.000
Prosocial behavior × Peer problems -.001 -.018 .016 .954 1.000
Y21
Vocabulary × Maternal Education -.016 -.043 .010 .219 1.000
Grammar × Maternal Education -.007 -.032 .019 .602 1.000
Parent-admin cognition × Maternal Education .019 -.007 .044 .147 1.000
Parent-report cognition × Maternal Education -.011 -.036 .014 .399 1.000
Conduct problems × Maternal Education -.001 -.024 .022 .914 1.000
Emotional problems × Maternal Education .001 -.023 .025 .963 1.000
Hyperactivity × Maternal Education .007 -.016 .029 .558 1.000
Peer problems × Maternal Education -.006 -.029 .018 .629 1.000
Prosocial behavior × Maternal Education -.006 -.031 .019 .631 1.000
Grammar × Vocabulary .005 -.009 .019 .483 1.000
Parent-admin cognition × Vocabulary -.003 -.026 .019 .802 1.000
Parent-report cognition × Vocabulary -.004 -.028 .019 .709 1.000
Conduct problems × Vocabulary .007 -.017 .032 .575 1.000
Emotional problems × Vocabulary -.001 -.025 .024 .966 1.000
Hyperactivity × Vocabulary .007 -.016 .031 .542 1.000
Peer problems × Vocabulary -.020 -.044 .005 .115 1.000
Prosocial behavior × Vocabulary .010 -.015 .034 .422 1.000
Parent-admin cognition × Grammar -.003 -.026 .020 .808 1.000
Parent-report cognition × Grammar .003 -.020 .026 .779 1.000
Conduct problems × Grammar -.002 -.026 .022 .875 1.000
Emotional problems × Grammar .002 -.023 .026 .903 1.000
Hyperactivity × Grammar .017 -.007 .040 .155 1.000
Peer problems × Grammar -.005 -.028 .018 .677 1.000
Prosocial behavior × Grammar -.004 -.028 .019 .747 1.000
Parent-report cognition × Parent-admin cognition .007 -.015 .029 .555 1.000
Conduct problems × Parent-admin cognition -.011 -.035 .013 .362 1.000
Emotional problems × Parent-admin cognition .017 -.007 .041 .177 1.000
Hyperactivity × Parent-admin cognition -.024 -.047 -.001 .041 1.000
Peer problems × Parent-admin cognition -.002 -.025 .022 .849 1.000
Prosocial behavior × Parent-admin cognition -.000 -.023 .023 .995 1.000
Conduct problems × Parent-report cognition .011 -.014 .037 .391 1.000
Emotional problems × Parent-report cognition .001 -.024 .025 .963 1.000
Hyperactivity × Parent-report cognition -.001 -.025 .023 .943 1.000
Peer problems × Parent-report cognition -.006 -.031 .019 .632 1.000
Prosocial behavior × Parent-report cognition -.011 -.034 .012 .348 1.000
Emotional problems × Conduct problems .010 -.014 .033 .394 1.000
Hyperactivity × Conduct problems -.011 -.031 .010 .308 1.000
Peer problems × Conduct problems -.023 -.048 .001 .065 1.000
Prosocial behavior × Conduct problems .010 -.014 .033 .389 1.000
Hyperactivity × Emotional problems -.025 -.048 -.003 .031 1.000
Peer problems × Emotional problems -.015 -.040 .009 .212 1.000
Prosocial behavior × Emotional problems .026 .004 .049 .023 1.000
Peer problems × Hyperactivity -.014 -.038 .010 .252 1.000
Prosocial behavior × Hyperactivity -.000 -.023 .023 .993 1.000
Prosocial behavior × Peer problems -.015 -.038 .007 .181 1.000
Y26 (q'aire)
Vocabulary × Maternal Education -.015 -.043 .013 .288 1.000
Grammar × Maternal Education -.000 -.028 .026 .975 1.000
Parent-admin cognition × Maternal Education .010 -.018 .038 .481 1.000
Parent-report cognition × Maternal Education -.012 -.041 .015 .388 1.000
Conduct problems × Maternal Education .000 -.025 .025 .998 1.000
Emotional problems × Maternal Education -.005 -.030 .022 .696 1.000
Hyperactivity × Maternal Education .001 -.023 .025 .935 1.000
Peer problems × Maternal Education -.016 -.042 .009 .208 1.000
Prosocial behavior × Maternal Education -.017 -.044 .010 .226 1.000
Grammar × Vocabulary -.005 -.020 .010 .538 1.000
Parent-admin cognition × Vocabulary .000 -.024 .024 .992 1.000
Parent-report cognition × Vocabulary -.011 -.036 .015 .416 1.000
Conduct problems × Vocabulary .008 -.020 .035 .581 1.000
Emotional problems × Vocabulary -.011 -.038 .016 .403 1.000
Hyperactivity × Vocabulary .004 -.022 .031 .774 1.000
Peer problems × Vocabulary -.013 -.039 .014 .333 1.000
Prosocial behavior × Vocabulary .003 -.023 .029 .793 1.000
Parent-admin cognition × Grammar -.004 -.029 .021 .733 1.000
Parent-report cognition × Grammar -.005 -.029 .020 .712 1.000
Conduct problems × Grammar -.005 -.031 .022 .715 1.000
Emotional problems × Grammar -.003 -.029 .023 .808 1.000
Hyperactivity × Grammar .015 -.011 .040 .266 1.000
Peer problems × Grammar -.007 -.033 .018 .578 1.000
Prosocial behavior × Grammar -.015 -.041 .011 .261 1.000
Parent-report cognition × Parent-admin cognition -.002 -.025 .021 .877 1.000
Conduct problems × Parent-admin cognition .011 -.015 .036 .420 1.000
Emotional problems × Parent-admin cognition .015 -.011 .041 .267 1.000
Hyperactivity × Parent-admin cognition -.014 -.039 .012 .305 1.000
Peer problems × Parent-admin cognition .015 -.010 .041 .244 1.000
Prosocial behavior × Parent-admin cognition -.005 -.031 .020 .695 1.000
Conduct problems × Parent-report cognition .019 -.008 .046 .175 1.000
Emotional problems × Parent-report cognition .002 -.025 .029 .878 1.000
Hyperactivity × Parent-report cognition -.016 -.041 .010 .237 1.000
Peer problems × Parent-report cognition -.004 -.030 .024 .793 1.000
Prosocial behavior × Parent-report cognition -.003 -.028 .021 .771 1.000
Emotional problems × Conduct problems .006 -.020 .031 .648 1.000
Hyperactivity × Conduct problems -.015 -.038 .006 .182 1.000
Peer problems × Conduct problems -.010 -.036 .017 .456 1.000
Prosocial behavior × Conduct problems .018 -.007 .043 .164 1.000
Hyperactivity × Emotional problems -.025 -.050 -.001 .041 1.000
Peer problems × Emotional problems -.006 -.033 .021 .664 1.000
Prosocial behavior × Emotional problems .017 -.007 .042 .163 1.000
Peer problems × Hyperactivity -.022 -.048 .004 .098 1.000
Prosocial behavior × Hyperactivity -.010 -.034 .014 .422 1.000
Prosocial behavior × Peer problems -.002 -.027 .022 .847 1.000
Y26 (web test)
Vocabulary × Maternal Education .021 -.027 .067 .375 1.000
Grammar × Maternal Education .031 -.013 .074 .165 1.000
Parent-admin cognition × Maternal Education .029 -.016 .074 .215 1.000
Parent-report cognition × Maternal Education .013 -.033 .058 .577 1.000
Conduct problems × Maternal Education .025 -.018 .067 .256 1.000
Emotional problems × Maternal Education .013 -.030 .057 .553 1.000
Hyperactivity × Maternal Education .001 -.040 .042 .982 1.000
Peer problems × Maternal Education .021 -.021 .063 .338 1.000
Prosocial behavior × Maternal Education .021 -.022 .064 .337 1.000
Grammar × Vocabulary .005 -.020 .029 .659 1.000
Parent-admin cognition × Vocabulary -.014 -.054 .025 .474 1.000
Parent-report cognition × Vocabulary -.013 -.056 .028 .533 1.000
Conduct problems × Vocabulary -.024 -.069 .021 .304 1.000
Emotional problems × Vocabulary -.020 -.064 .023 .358 1.000
Hyperactivity × Vocabulary .016 -.026 .058 .458 1.000
Peer problems × Vocabulary -.032 -.076 .010 .144 1.000
Prosocial behavior × Vocabulary .032 -.012 .075 .148 1.000
Parent-admin cognition × Grammar -.010 -.052 .031 .620 1.000
Parent-report cognition × Grammar -.015 -.056 .025 .465 1.000
Conduct problems × Grammar -.019 -.061 .025 .392 1.000
Emotional problems × Grammar .000 -.043 .043 .984 1.000
Hyperactivity × Grammar .027 -.015 .070 .207 1.000
Peer problems × Grammar -.017 -.059 .024 .409 1.000
Prosocial behavior × Grammar .007 -.036 .048 .752 1.000
Parent-report cognition × Parent-admin cognition -.028 -.066 .010 .148 1.000
Conduct problems × Parent-admin cognition -.020 -.062 .022 .349 1.000
Emotional problems × Parent-admin cognition -.007 -.049 .036 .745 1.000
Hyperactivity × Parent-admin cognition -.001 -.043 .041 .963 1.000
Peer problems × Parent-admin cognition -.015 -.056 .025 .462 1.000
Prosocial behavior × Parent-admin cognition .009 -.031 .049 .636 1.000
Conduct problems × Parent-report cognition .015 -.028 .060 .510 1.000
Emotional problems × Parent-report cognition -.013 -.055 .029 .556 1.000
Hyperactivity × Parent-report cognition .006 -.034 .046 .775 1.000
Peer problems × Parent-report cognition -.009 -.052 .034 .702 1.000
Prosocial behavior × Parent-report cognition .001 -.039 .041 .933 1.000
Emotional problems × Conduct problems .041 .002 .081 .040 1.000
Hyperactivity × Conduct problems -.016 -.052 .019 .392 1.000
Peer problems × Conduct problems -.010 -.050 .031 .644 1.000
Prosocial behavior × Conduct problems .014 -.026 .057 .501 1.000
Hyperactivity × Emotional problems -.002 -.042 .037 .909 1.000
Peer problems × Emotional problems .015 -.028 .056 .493 1.000
Prosocial behavior × Emotional problems .023 -.018 .064 .275 1.000
Peer problems × Hyperactivity -.019 -.062 .023 .375 1.000
Prosocial behavior × Hyperactivity -.010 -.051 .032 .646 1.000
Prosocial behavior × Peer problems -.014 -.055 .026 .485 1.000
Note. Est = Estimate, LB = Lower Bound 95% Confidence Interval, UB = Upper Bound 95% Confidence Interval. Significant (pBonferroni-Holm) effects are highlighted in green (increases) or red (decreases).
* P values are Bonferroni-Holm adjusted within each attrition timepoint

Plot Original Correlations between variables

Code
df %>%
  filter(!(randomfamid %in% exclude_fams_onesib)) %>% 
  select(rq2y) %>%
  data.frame() %>%
  `colnames<-`(rq2y_labels_short) %>%
   gbtoolbox::plot_correlations() +
  labs(title = "Original (un-attritioned) correlations")
Warning in gbtoolbox::plot_correlations(.): This function is in development, and not yet ready for widespread use. 
  Proceed with caution
Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
ℹ Please use `all_of()` or `any_of()` instead.
  # Was:
  data %>% select(rq2y)

  # Now:
  data %>% select(all_of(rq2y))

See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.

Code
save_plot(
  "2_rq2_2_correlations_original", width = 8, height = 8)

📊 View Plot

ACE Comparison

Count of significant ACE differences (unadjusted)

Code
bootstrap_summary_df_ace %>%
  filter(group == "Difference") %>% 
  summarise(
    total_tests = dplyr::n(),
    sig_unadj = sum(pval < 0.05),
    pct_sig = round(sig_unadj / total_tests * 100, 1)
  )

ACE differences tables (p(unadjusted) < .05)

Code
bootstrap_summary_df_ace %>%
  filter(group == "Difference") %>%
  group_by(dataset_label) %>%
  mutate(
    pval_adj = stats::p.adjust(pval, method = "holm"),
    n_adj    = dplyr::n(),
    name     = rq2y_labels_short[match(name, rq2y)]
  ) %>%
  ungroup() %>%
  arrange(name, par, dataset_label) %>%
  filter(pval < .05) %>%
  select(-starts_with("."), -dataset, -group, -n, -pd, -n_adj) %>%
  mutate(
    par = toupper(par),
    sex = str_to_title(sex),
    row_num = row_number()
  ) %>%
  relocate(row_num, dataset_label, name, par, sex, y, ymin, ymax, pval, pval_adj) %>%
  gt() %>%
  cols_label(
    row_num = "",
    dataset_label = "Timepoint",
    name = "Variable",
    par = "Par",
    sex = "Sex",
    y = "Est",
    ymin = "LB",
    ymax = "UB",
    pval = md("p<sub>unadj</sub>"),
    pval_adj = md("p<sub>adj</sub>")
  ) %>%
  tab_spanner(
    label = "ACE Difference (Attritioned - Original)",
    columns = c(y, ymin, ymax, pval, pval_adj)
  ) %>%
  fmt(
    columns = c(y, ymin, ymax, pval, pval_adj),
    fns = function(x) {gbtoolbox::apa_num(x, n_decimal_places = 3)}
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_column_spanners()
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_body()
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_column_labels()
  ) %>%
  tab_style(
    style = cell_text(size = px(10)),
    locations = cells_footnotes()
  ) %>%
  tab_footnote(
    footnote = md("<em>Note.</em> Est = Estimate, LB = Lower Bound 95% CI, UB = Upper Bound 95% CI, Par = ACE Parameter. Only effects with p<sub>unadjusted</sub> < .05 are shown."),
    placement = "right"
  ) %>%
  tab_footnote(
    footnote = "P values are Bonferroni-Holm adjusted within each sex, parameter, and timepoint",
    locations = cells_column_labels(columns = pval_adj),
    placement = "right"
  ) %>%
  opt_footnote_marks(marks = c("*", "†"))
Timepoint Variable Par Sex
ACE Difference (Attritioned - Original)
Est LB UB punadj padj*
1 Y26 (web test) Conduct problems E Male -.224 -.311 -.132 .000 .000
2 Y16 (q'aire) Grammar A Male -.166 -.293 -.038 .012 .624
3 Y12 (web test) Grammar C Female .103 .015 .193 .022 1.000
4 Y16 (q'aire) Grammar C Male .157 .044 .271 .007 .367
5 Y4 Grammar C Male .062 .004 .124 .036 1.000
6 Y12 (q'aire) Grammar E Male -.029 -.056 -.003 .028 1.000
7 Y26 (q'aire) Hyperactivity A Male .101 .003 .192 .043 1.000
8 Y26 (q'aire) Hyperactivity E Male -.102 -.192 -.006 .038 1.000
9 Y12 (web test) Parent-admin cognition E Male .034 .001 .069 .042 1.000
10 Y16 (q'aire) Parent-admin cognition E Female .042 .010 .076 .009 .477
11 Y4 Parent-admin cognition E Female .023 .003 .042 .024 1.000
12 Y26 (q'aire) Parent-report cognition E Female -.062 -.119 -.006 .030 1.000
13 Y26 (web test) Parent-report cognition E Female -.073 -.140 -.004 .040 1.000
14 Y16 (q'aire) Peer problems A Male -.077 -.157 -.004 .040 1.000
15 Y26 (q'aire) Peer problems A Female -.098 -.279 -.012 .020 1.000
16 Y16 (q'aire) Peer problems E Male .076 .004 .152 .040 1.000
17 Y26 (q'aire) Peer problems E Female .073 .010 .140 .023 1.000
18 Y26 (web test) Vocabulary A Male -.087 -.170 -.001 .046 1.000
19 Y16 (q'aire) Vocabulary C Male .069 .006 .132 .034 1.000
20 Y26 (web test) Vocabulary C Male .111 .029 .190 .010 .541
21 Y12 (web test) Vocabulary E Female -.024 -.041 -.008 .002 .108
22 Y12 (web test) Vocabulary E Male -.012 -.024 -.001 .032 1.000
23 Y16 (q'aire) Vocabulary E Male -.013 -.026 -.001 .025 1.000
24 Y26 (q'aire) Vocabulary E Female -.021 -.040 -.003 .028 1.000
25 Y26 (q'aire) Vocabulary E Male -.018 -.032 -.005 .003 .173
26 Y26 (web test) Vocabulary E Female -.026 -.047 -.006 .012 .602
27 Y26 (web test) Vocabulary E Male -.024 -.039 -.011 .001 .053
Note. Est = Estimate, LB = Lower Bound 95% CI, UB = Upper Bound 95% CI, Par = ACE Parameter. Only effects with punadjusted < .05 are shown.
* P values are Bonferroni-Holm adjusted within each sex, parameter, and timepoint

ACE Estimates & Differences Table (complete)

Code
bootstrap_summary_df_ace %>%
  filter(par %in% c("a","c","e")) %>%
  group_by(dataset_label) %>%
  mutate(
    pval = stats::p.adjust(pval, method = "holm"),
  ) %>%
  ungroup() %>%
  select(-starts_with("."), -n, -pd) %>%
  mutate(name_clean = rq2y_labels_short[match(name, rq2y)]) %>%
  pivot_wider(
    id_cols = c(par, name_clean, sex, dataset_label),
    names_from = group,
    values_from = c(y, ymin, ymax, pval),
    names_sep = "_"
  ) %>%
  select(-ymin_Original, -ymax_Original, -ymin_Attritioned, -ymax_Attritioned, -pval_Original, -pval_Attritioned) %>%
  select(dataset_label, name_clean, par, y_Original, y_Attritioned, y_Difference, ymin_Difference, ymax_Difference, pval_Difference, sex) %>%
  mutate(
    name_clean    = factor(name_clean,    levels = rq2y_labels_short),
    dataset_label = factor(dataset_label, levels = rq1y_twin_labels_clean_extrashort)
    ) %>% 
  arrange(sex, dataset_label, name_clean, par) %>%
  mutate(par = toupper(par)) %>%
  gt(groupname_col = "sex") %>%
  fmt_number(decimals = 3) %>%
  tab_row_group(
    label = "Male",
    rows = sex == "male"
  ) %>%
  tab_row_group(
    label = "Female",
    rows = sex == "female"
  ) %>%
  cols_hide(sex) %>%
  cols_label(
    dataset_label = "Timepoint",
    name_clean = "Variable",
    par = "",
    y_Original = "Original",
    y_Attritioned = "Attritioned",
    y_Difference = "Diff",
    ymin_Difference = "Lower",
    ymax_Difference = "Upper",
    pval_Difference = "p"
  ) %>%
  tab_spanner(
    label = "95% CI",
    columns = c(ymin_Difference, ymax_Difference)
  ) %>%
  tab_spanner(
    label = "Estimates",
    columns = c(y_Attritioned, y_Original)
  ) %>%
  tab_style(
    style = cell_fill(color = "lightgreen"),
    locations = cells_body(
      columns = everything(),
      rows = pval_Difference < 0.05
    )
  ) %>%
  tab_footnote(
    footnote = "P values are Bonferroni-Holm adjusted within each sex, parameter (A, C or E), and timepoint group",
    locations = cells_column_labels(columns = pval_Difference)
  )
Timepoint Variable
Estimates
Diff
95% CI
p1
Attritioned Original Lower Upper
Female
Y4 Vocabulary A 0.118 0.130 −0.012 −0.055 0.026 1.000
Y4 Vocabulary C 0.817 0.809 0.008 −0.026 0.049 1.000
Y4 Vocabulary E 0.065 0.061 0.004 −0.006 0.013 1.000
Y4 Grammar A 0.346 0.328 0.017 −0.046 0.079 1.000
Y4 Grammar C 0.512 0.526 −0.014 −0.069 0.042 1.000
Y4 Grammar E 0.142 0.145 −0.003 −0.020 0.013 1.000
Y4 Parent-admin cognition A 0.191 0.220 −0.029 −0.098 0.039 1.000
Y4 Parent-admin cognition C 0.510 0.504 0.006 −0.054 0.069 1.000
Y4 Parent-admin cognition E 0.298 0.276 0.023 0.003 0.042 1.000
Y4 Parent-report cognition A 0.071 0.136 −0.065 −0.175 0.025 1.000
Y4 Parent-report cognition C 0.720 0.665 0.055 −0.022 0.154 1.000
Y4 Parent-report cognition E 0.209 0.199 0.010 −0.017 0.035 1.000
Y4 Conduct problems A 0.357 0.455 −0.099 −0.216 0.011 1.000
Y4 Conduct problems C 0.125 0.045 0.080 0.000 0.177 1.000
Y4 Conduct problems E 0.518 0.500 0.019 −0.020 0.055 1.000
Y4 Emotional problems A 0.550 0.528 0.022 −0.055 0.117 1.000
Y4 Emotional problems C 0.032 0.062 −0.030 −0.110 0.034 1.000
Y4 Emotional problems E 0.418 0.410 0.008 −0.025 0.040 1.000
Y4 Hyperactivity A 0.616 0.625 −0.009 −0.038 0.022 1.000
Y4 Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y4 Hyperactivity E 0.384 0.375 0.009 −0.022 0.038 1.000
Y4 Peer problems A 0.519 0.520 −0.001 −0.041 0.033 1.000
Y4 Peer problems C 0.002 0.001 0.001 0.000 0.024 1.000
Y4 Peer problems E 0.479 0.480 0.000 −0.032 0.032 1.000
Y4 Prosocial behavior A 0.341 0.329 0.012 −0.072 0.096 1.000
Y4 Prosocial behavior C 0.406 0.402 0.004 −0.067 0.078 1.000
Y4 Prosocial behavior E 0.253 0.269 −0.016 −0.043 0.008 1.000
Y12 (web test) Vocabulary A 0.154 0.130 0.025 −0.037 0.085 1.000
Y12 (web test) Vocabulary C 0.808 0.809 −0.001 −0.054 0.054 1.000
Y12 (web test) Vocabulary E 0.038 0.061 −0.024 −0.041 −0.008 0.146
Y12 (web test) Grammar A 0.235 0.329 −0.094 −0.193 0.004 1.000
Y12 (web test) Grammar C 0.628 0.525 0.103 0.015 0.193 1.000
Y12 (web test) Grammar E 0.136 0.145 −0.009 −0.035 0.015 1.000
Y12 (web test) Parent-admin cognition A 0.161 0.220 −0.059 −0.161 0.042 1.000
Y12 (web test) Parent-admin cognition C 0.538 0.504 0.034 −0.052 0.123 1.000
Y12 (web test) Parent-admin cognition E 0.301 0.275 0.025 −0.007 0.056 1.000
Y12 (web test) Parent-report cognition A 0.101 0.135 −0.034 −0.167 0.101 1.000
Y12 (web test) Parent-report cognition C 0.709 0.666 0.043 −0.060 0.156 1.000
Y12 (web test) Parent-report cognition E 0.190 0.199 −0.009 −0.057 0.033 1.000
Y12 (web test) Conduct problems A 0.466 0.455 0.011 −0.142 0.133 1.000
Y12 (web test) Conduct problems C 0.075 0.045 0.029 −0.065 0.153 1.000
Y12 (web test) Conduct problems E 0.460 0.499 −0.040 −0.093 0.012 1.000
Y12 (web test) Emotional problems A 0.510 0.526 −0.016 −0.169 0.119 1.000
Y12 (web test) Emotional problems C 0.078 0.064 0.014 −0.093 0.141 1.000
Y12 (web test) Emotional problems E 0.412 0.410 0.002 −0.049 0.051 1.000
Y12 (web test) Hyperactivity A 0.646 0.625 0.021 −0.024 0.065 1.000
Y12 (web test) Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y12 (web test) Hyperactivity E 0.354 0.375 −0.021 −0.065 0.024 1.000
Y12 (web test) Peer problems A 0.541 0.519 0.022 −0.030 0.076 1.000
Y12 (web test) Peer problems C 0.000 0.001 −0.001 −0.006 0.000 1.000
Y12 (web test) Peer problems E 0.459 0.480 −0.021 −0.072 0.030 1.000
Y12 (web test) Prosocial behavior A 0.285 0.329 −0.044 −0.153 0.064 1.000
Y12 (web test) Prosocial behavior C 0.434 0.401 0.033 −0.064 0.131 1.000
Y12 (web test) Prosocial behavior E 0.281 0.270 0.011 −0.020 0.041 1.000
Y12 (q'aire) Vocabulary A 0.149 0.130 0.019 −0.036 0.073 1.000
Y12 (q'aire) Vocabulary C 0.798 0.809 −0.011 −0.058 0.038 1.000
Y12 (q'aire) Vocabulary E 0.053 0.061 −0.008 −0.024 0.006 1.000
Y12 (q'aire) Grammar A 0.266 0.329 −0.063 −0.155 0.025 1.000
Y12 (q'aire) Grammar C 0.587 0.525 0.062 −0.016 0.145 1.000
Y12 (q'aire) Grammar E 0.146 0.145 0.001 −0.022 0.024 1.000
Y12 (q'aire) Parent-admin cognition A 0.192 0.221 −0.029 −0.124 0.065 1.000
Y12 (q'aire) Parent-admin cognition C 0.510 0.504 0.007 −0.075 0.089 1.000
Y12 (q'aire) Parent-admin cognition E 0.298 0.276 0.022 −0.009 0.052 1.000
Y12 (q'aire) Parent-report cognition A 0.153 0.137 0.017 −0.119 0.148 1.000
Y12 (q'aire) Parent-report cognition C 0.658 0.665 −0.007 −0.108 0.107 1.000
Y12 (q'aire) Parent-report cognition E 0.189 0.198 −0.010 −0.056 0.034 1.000
Y12 (q'aire) Conduct problems A 0.469 0.456 0.013 −0.111 0.122 1.000
Y12 (q'aire) Conduct problems C 0.042 0.045 −0.003 −0.089 0.098 1.000
Y12 (q'aire) Conduct problems E 0.489 0.500 −0.010 −0.059 0.036 1.000
Y12 (q'aire) Emotional problems A 0.540 0.525 0.014 −0.103 0.134 1.000
Y12 (q'aire) Emotional problems C 0.037 0.064 −0.027 −0.123 0.066 1.000
Y12 (q'aire) Emotional problems E 0.423 0.411 0.013 −0.034 0.059 1.000
Y12 (q'aire) Hyperactivity A 0.641 0.625 0.016 −0.027 0.062 1.000
Y12 (q'aire) Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y12 (q'aire) Hyperactivity E 0.359 0.375 −0.016 −0.062 0.027 1.000
Y12 (q'aire) Peer problems A 0.524 0.520 0.004 −0.043 0.051 1.000
Y12 (q'aire) Peer problems C 0.000 0.001 0.000 −0.001 0.000 1.000
Y12 (q'aire) Peer problems E 0.476 0.480 −0.003 −0.049 0.043 1.000
Y12 (q'aire) Prosocial behavior A 0.338 0.329 0.010 −0.093 0.114 1.000
Y12 (q'aire) Prosocial behavior C 0.373 0.402 −0.028 −0.123 0.065 1.000
Y12 (q'aire) Prosocial behavior E 0.288 0.270 0.018 −0.011 0.048 1.000
Y16 (q'aire) Vocabulary A 0.165 0.129 0.036 −0.026 0.102 1.000
Y16 (q'aire) Vocabulary C 0.781 0.809 −0.028 −0.087 0.028 1.000
Y16 (q'aire) Vocabulary E 0.054 0.062 −0.008 −0.025 0.009 1.000
Y16 (q'aire) Grammar A 0.266 0.329 −0.064 −0.165 0.036 1.000
Y16 (q'aire) Grammar C 0.574 0.526 0.048 −0.041 0.139 1.000
Y16 (q'aire) Grammar E 0.161 0.145 0.016 −0.009 0.041 1.000
Y16 (q'aire) Parent-admin cognition A 0.159 0.221 −0.061 −0.164 0.040 1.000
Y16 (q'aire) Parent-admin cognition C 0.523 0.504 0.020 −0.070 0.109 1.000
Y16 (q'aire) Parent-admin cognition E 0.317 0.276 0.042 0.010 0.076 0.648
Y16 (q'aire) Parent-report cognition A 0.071 0.134 −0.063 −0.200 0.069 1.000
Y16 (q'aire) Parent-report cognition C 0.726 0.666 0.060 −0.045 0.177 1.000
Y16 (q'aire) Parent-report cognition E 0.203 0.199 0.004 −0.041 0.045 1.000
Y16 (q'aire) Conduct problems A 0.462 0.456 0.006 −0.119 0.130 1.000
Y16 (q'aire) Conduct problems C 0.026 0.044 −0.018 −0.118 0.079 1.000
Y16 (q'aire) Conduct problems E 0.511 0.500 0.012 −0.045 0.067 1.000
Y16 (q'aire) Emotional problems A 0.537 0.527 0.010 −0.132 0.142 1.000
Y16 (q'aire) Emotional problems C 0.044 0.063 −0.019 −0.125 0.096 1.000
Y16 (q'aire) Emotional problems E 0.419 0.410 0.009 −0.046 0.062 1.000
Y16 (q'aire) Hyperactivity A 0.631 0.625 0.006 −0.042 0.053 1.000
Y16 (q'aire) Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y16 (q'aire) Hyperactivity E 0.369 0.375 −0.006 −0.053 0.042 1.000
Y16 (q'aire) Peer problems A 0.490 0.520 −0.029 −0.088 0.027 1.000
Y16 (q'aire) Peer problems C 0.002 0.001 0.001 0.000 0.015 1.000
Y16 (q'aire) Peer problems E 0.508 0.480 0.028 −0.026 0.083 1.000
Y16 (q'aire) Prosocial behavior A 0.353 0.328 0.025 −0.094 0.144 1.000
Y16 (q'aire) Prosocial behavior C 0.375 0.402 −0.027 −0.137 0.082 1.000
Y16 (q'aire) Prosocial behavior E 0.272 0.270 0.002 −0.031 0.034 1.000
Y18 Vocabulary A 0.128 0.130 −0.002 −0.061 0.054 1.000
Y18 Vocabulary C 0.817 0.809 0.009 −0.040 0.062 1.000
Y18 Vocabulary E 0.055 0.061 −0.007 −0.022 0.007 1.000
Y18 Grammar A 0.335 0.329 0.006 −0.080 0.091 1.000
Y18 Grammar C 0.514 0.526 −0.011 −0.092 0.068 1.000
Y18 Grammar E 0.151 0.145 0.006 −0.014 0.026 1.000
Y18 Parent-admin cognition A 0.212 0.221 −0.009 −0.100 0.082 1.000
Y18 Parent-admin cognition C 0.497 0.503 −0.006 −0.083 0.074 1.000
Y18 Parent-admin cognition E 0.291 0.275 0.015 −0.014 0.041 1.000
Y18 Parent-report cognition A 0.121 0.136 −0.015 −0.140 0.108 1.000
Y18 Parent-report cognition C 0.684 0.665 0.019 −0.078 0.125 1.000
Y18 Parent-report cognition E 0.195 0.199 −0.004 −0.045 0.031 1.000
Y18 Conduct problems A 0.442 0.455 −0.013 −0.144 0.096 1.000
Y18 Conduct problems C 0.055 0.045 0.010 −0.077 0.118 1.000
Y18 Conduct problems E 0.503 0.500 0.003 −0.041 0.047 1.000
Y18 Emotional problems A 0.543 0.526 0.018 −0.096 0.132 1.000
Y18 Emotional problems C 0.038 0.064 −0.025 −0.123 0.071 1.000
Y18 Emotional problems E 0.418 0.410 0.008 −0.034 0.050 1.000
Y18 Hyperactivity A 0.621 0.625 −0.004 −0.041 0.035 1.000
Y18 Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y18 Hyperactivity E 0.379 0.375 0.004 −0.035 0.041 1.000
Y18 Peer problems A 0.484 0.519 −0.035 −0.078 0.008 1.000
Y18 Peer problems C 0.001 0.001 0.000 0.000 0.000 1.000
Y18 Peer problems E 0.515 0.480 0.035 −0.006 0.075 1.000
Y18 Prosocial behavior A 0.308 0.327 −0.019 −0.114 0.076 1.000
Y18 Prosocial behavior C 0.429 0.403 0.026 −0.062 0.113 1.000
Y18 Prosocial behavior E 0.264 0.270 −0.006 −0.032 0.019 1.000
Y21 Vocabulary A 0.155 0.129 0.026 −0.043 0.099 1.000
Y21 Vocabulary C 0.796 0.809 −0.014 −0.080 0.048 1.000
Y21 Vocabulary E 0.049 0.062 −0.012 −0.030 0.004 1.000
Y21 Grammar A 0.257 0.330 −0.073 −0.185 0.039 1.000
Y21 Grammar C 0.600 0.525 0.075 −0.028 0.178 1.000
Y21 Grammar E 0.143 0.145 −0.002 −0.029 0.024 1.000
Y21 Parent-admin cognition A 0.216 0.219 −0.003 −0.112 0.109 1.000
Y21 Parent-admin cognition C 0.522 0.505 0.016 −0.079 0.111 1.000
Y21 Parent-admin cognition E 0.262 0.276 −0.014 −0.046 0.018 1.000
Y21 Parent-report cognition A 0.067 0.135 −0.068 −0.206 0.063 1.000
Y21 Parent-report cognition C 0.747 0.666 0.081 −0.026 0.201 1.000
Y21 Parent-report cognition E 0.187 0.199 −0.012 −0.058 0.029 1.000
Y21 Conduct problems A 0.320 0.455 −0.135 −0.329 0.031 1.000
Y21 Conduct problems C 0.166 0.045 0.120 −0.006 0.282 1.000
Y21 Conduct problems E 0.514 0.500 0.015 −0.044 0.072 1.000
Y21 Emotional problems A 0.467 0.526 −0.058 −0.244 0.099 1.000
Y21 Emotional problems C 0.129 0.064 0.065 −0.063 0.224 1.000
Y21 Emotional problems E 0.404 0.411 −0.007 −0.062 0.048 1.000
Y21 Hyperactivity A 0.631 0.625 0.006 −0.042 0.053 1.000
Y21 Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y21 Hyperactivity E 0.369 0.375 −0.006 −0.053 0.042 1.000
Y21 Peer problems A 0.450 0.519 −0.069 −0.218 0.000 1.000
Y21 Peer problems C 0.019 0.001 0.019 0.000 0.154 1.000
Y21 Peer problems E 0.530 0.480 0.050 −0.002 0.103 1.000
Y21 Prosocial behavior A 0.327 0.329 −0.002 −0.135 0.133 1.000
Y21 Prosocial behavior C 0.405 0.402 0.004 −0.120 0.126 1.000
Y21 Prosocial behavior E 0.268 0.270 −0.002 −0.036 0.031 1.000
Y26 (q'aire) Vocabulary A 0.207 0.129 0.077 −0.004 0.168 1.000
Y26 (q'aire) Vocabulary C 0.753 0.809 −0.056 −0.142 0.020 1.000
Y26 (q'aire) Vocabulary E 0.041 0.061 −0.021 −0.040 −0.003 1.000
Y26 (q'aire) Grammar A 0.220 0.329 −0.109 −0.235 0.018 1.000
Y26 (q'aire) Grammar C 0.620 0.526 0.094 −0.022 0.207 1.000
Y26 (q'aire) Grammar E 0.161 0.145 0.016 −0.016 0.048 1.000
Y26 (q'aire) Parent-admin cognition A 0.250 0.220 0.030 −0.096 0.157 1.000
Y26 (q'aire) Parent-admin cognition C 0.479 0.504 −0.026 −0.137 0.085 1.000
Y26 (q'aire) Parent-admin cognition E 0.272 0.276 −0.004 −0.041 0.033 1.000
Y26 (q'aire) Parent-report cognition A 0.217 0.134 0.083 −0.090 0.248 1.000
Y26 (q'aire) Parent-report cognition C 0.646 0.667 −0.021 −0.155 0.121 1.000
Y26 (q'aire) Parent-report cognition E 0.137 0.199 −0.062 −0.119 −0.006 1.000
Y26 (q'aire) Conduct problems A 0.432 0.455 −0.023 −0.200 0.120 1.000
Y26 (q'aire) Conduct problems C 0.049 0.045 0.003 −0.105 0.145 1.000
Y26 (q'aire) Conduct problems E 0.519 0.500 0.020 −0.050 0.089 1.000
Y26 (q'aire) Emotional problems A 0.502 0.527 −0.025 −0.222 0.131 1.000
Y26 (q'aire) Emotional problems C 0.083 0.063 0.020 −0.106 0.185 1.000
Y26 (q'aire) Emotional problems E 0.415 0.410 0.005 −0.059 0.069 1.000
Y26 (q'aire) Hyperactivity A 0.588 0.625 −0.038 −0.099 0.021 1.000
Y26 (q'aire) Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y26 (q'aire) Hyperactivity E 0.412 0.375 0.037 −0.021 0.099 1.000
Y26 (q'aire) Peer problems A 0.423 0.520 −0.098 −0.279 −0.012 1.000
Y26 (q'aire) Peer problems C 0.025 0.001 0.024 0.000 0.179 1.000
Y26 (q'aire) Peer problems E 0.552 0.479 0.073 0.010 0.140 1.000
Y26 (q'aire) Prosocial behavior A 0.295 0.329 −0.034 −0.181 0.118 1.000
Y26 (q'aire) Prosocial behavior C 0.434 0.401 0.033 −0.105 0.164 1.000
Y26 (q'aire) Prosocial behavior E 0.270 0.269 0.001 −0.038 0.042 1.000
Y26 (web test) Vocabulary A 0.168 0.129 0.039 −0.078 0.171 1.000
Y26 (web test) Vocabulary C 0.796 0.809 −0.013 −0.141 0.097 1.000
Y26 (web test) Vocabulary E 0.035 0.062 −0.026 −0.047 −0.006 0.932
Y26 (web test) Grammar A 0.335 0.328 0.006 −0.221 0.257 1.000
Y26 (web test) Grammar C 0.531 0.526 0.004 −0.232 0.213 1.000
Y26 (web test) Grammar E 0.134 0.145 −0.011 −0.058 0.042 1.000
Y26 (web test) Parent-admin cognition A 0.201 0.221 −0.019 −0.207 0.182 1.000
Y26 (web test) Parent-admin cognition C 0.492 0.504 −0.012 −0.191 0.154 1.000
Y26 (web test) Parent-admin cognition E 0.307 0.276 0.032 −0.023 0.091 1.000
Y26 (web test) Parent-report cognition A 0.131 0.133 −0.002 −0.189 0.188 1.000
Y26 (web test) Parent-report cognition C 0.742 0.667 0.075 −0.075 0.223 1.000
Y26 (web test) Parent-report cognition E 0.127 0.199 −0.073 −0.140 −0.004 1.000
Y26 (web test) Conduct problems A 0.277 0.455 −0.178 −0.478 0.088 1.000
Y26 (web test) Conduct problems C 0.178 0.045 0.132 −0.077 0.397 1.000
Y26 (web test) Conduct problems E 0.545 0.499 0.045 −0.063 0.156 1.000
Y26 (web test) Emotional problems A 0.466 0.526 −0.061 −0.389 0.192 1.000
Y26 (web test) Emotional problems C 0.170 0.063 0.108 −0.107 0.394 1.000
Y26 (web test) Emotional problems E 0.364 0.411 −0.047 −0.137 0.048 1.000
Y26 (web test) Hyperactivity A 0.529 0.625 −0.096 −0.422 0.067 1.000
Y26 (web test) Hyperactivity C 0.069 0.000 0.069 0.000 0.339 1.000
Y26 (web test) Hyperactivity E 0.402 0.375 0.027 −0.072 0.138 1.000
Y26 (web test) Peer problems A 0.381 0.520 −0.139 −0.404 0.003 1.000
Y26 (web test) Peer problems C 0.034 0.001 0.033 0.000 0.243 1.000
Y26 (web test) Peer problems E 0.585 0.479 0.106 −0.006 0.223 1.000
Y26 (web test) Prosocial behavior A 0.133 0.328 −0.196 −0.380 0.057 1.000
Y26 (web test) Prosocial behavior C 0.571 0.402 0.169 −0.061 0.340 1.000
Y26 (web test) Prosocial behavior E 0.297 0.270 0.027 −0.037 0.093 1.000
Male
Y4 Vocabulary A 0.169 0.183 −0.013 −0.059 0.026 1.000
Y4 Vocabulary C 0.789 0.776 0.013 −0.024 0.056 1.000
Y4 Vocabulary E 0.042 0.041 0.001 −0.007 0.008 1.000
Y4 Grammar A 0.304 0.365 −0.061 −0.129 0.007 1.000
Y4 Grammar C 0.552 0.490 0.062 0.004 0.124 1.000
Y4 Grammar E 0.143 0.145 −0.002 −0.021 0.015 1.000
Y4 Parent-admin cognition A 0.242 0.245 −0.002 −0.075 0.066 1.000
Y4 Parent-admin cognition C 0.496 0.494 0.002 −0.058 0.066 1.000
Y4 Parent-admin cognition E 0.261 0.261 0.000 −0.021 0.020 1.000
Y4 Parent-report cognition A 0.288 0.311 −0.024 −0.129 0.072 1.000
Y4 Parent-report cognition C 0.581 0.549 0.032 −0.049 0.128 1.000
Y4 Parent-report cognition E 0.132 0.140 −0.008 −0.036 0.014 1.000
Y4 Conduct problems A 0.573 0.564 0.009 −0.032 0.054 1.000
Y4 Conduct problems C 0.001 0.002 −0.001 −0.018 0.000 1.000
Y4 Conduct problems E 0.427 0.435 −0.008 −0.049 0.031 1.000
Y4 Emotional problems A 0.616 0.589 0.027 −0.027 0.105 1.000
Y4 Emotional problems C 0.009 0.015 −0.007 −0.065 0.026 1.000
Y4 Emotional problems E 0.376 0.396 −0.020 −0.060 0.017 1.000
Y4 Hyperactivity A 0.627 0.635 −0.008 −0.045 0.029 1.000
Y4 Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y4 Hyperactivity E 0.373 0.365 0.008 −0.029 0.045 1.000
Y4 Peer problems A 0.578 0.565 0.014 −0.022 0.051 1.000
Y4 Peer problems C 0.000 0.000 0.000 0.000 0.000 1.000
Y4 Peer problems E 0.421 0.435 −0.014 −0.051 0.022 1.000
Y4 Prosocial behavior A 0.411 0.438 −0.027 −0.098 0.042 1.000
Y4 Prosocial behavior C 0.368 0.329 0.039 −0.022 0.103 1.000
Y4 Prosocial behavior E 0.221 0.233 −0.012 −0.032 0.008 1.000
Y12 (web test) Vocabulary A 0.174 0.183 −0.009 −0.072 0.053 1.000
Y12 (web test) Vocabulary C 0.797 0.776 0.020 −0.038 0.081 1.000
Y12 (web test) Vocabulary E 0.029 0.041 −0.012 −0.024 −0.001 1.000
Y12 (web test) Grammar A 0.339 0.365 −0.026 −0.139 0.086 1.000
Y12 (web test) Grammar C 0.537 0.490 0.047 −0.057 0.149 1.000
Y12 (web test) Grammar E 0.125 0.145 −0.020 −0.048 0.007 1.000
Y12 (web test) Parent-admin cognition A 0.238 0.244 −0.006 −0.122 0.115 1.000
Y12 (web test) Parent-admin cognition C 0.467 0.495 −0.028 −0.136 0.078 1.000
Y12 (web test) Parent-admin cognition E 0.295 0.262 0.034 0.001 0.069 1.000
Y12 (web test) Parent-report cognition A 0.294 0.311 −0.017 −0.152 0.118 1.000
Y12 (web test) Parent-report cognition C 0.586 0.549 0.037 −0.079 0.160 1.000
Y12 (web test) Parent-report cognition E 0.120 0.140 −0.020 −0.058 0.013 1.000
Y12 (web test) Conduct problems A 0.540 0.564 −0.024 −0.128 0.048 1.000
Y12 (web test) Conduct problems C 0.008 0.001 0.006 −0.002 0.086 1.000
Y12 (web test) Conduct problems E 0.452 0.434 0.018 −0.046 0.082 1.000
Y12 (web test) Emotional problems A 0.561 0.589 −0.028 −0.196 0.084 1.000
Y12 (web test) Emotional problems C 0.053 0.015 0.037 −0.037 0.170 1.000
Y12 (web test) Emotional problems E 0.386 0.396 −0.010 −0.071 0.051 1.000
Y12 (web test) Hyperactivity A 0.616 0.635 −0.019 −0.079 0.037 1.000
Y12 (web test) Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y12 (web test) Hyperactivity E 0.384 0.365 0.019 −0.037 0.079 1.000
Y12 (web test) Peer problems A 0.519 0.565 −0.045 −0.111 0.015 1.000
Y12 (web test) Peer problems C 0.001 0.000 0.001 0.000 0.005 1.000
Y12 (web test) Peer problems E 0.479 0.435 0.044 −0.015 0.105 1.000
Y12 (web test) Prosocial behavior A 0.420 0.439 −0.020 −0.146 0.108 1.000
Y12 (web test) Prosocial behavior C 0.364 0.328 0.036 −0.078 0.150 1.000
Y12 (web test) Prosocial behavior E 0.216 0.233 −0.017 −0.051 0.017 1.000
Y12 (q'aire) Vocabulary A 0.182 0.184 −0.002 −0.062 0.058 1.000
Y12 (q'aire) Vocabulary C 0.786 0.775 0.011 −0.046 0.068 1.000
Y12 (q'aire) Vocabulary E 0.032 0.041 −0.009 −0.022 0.001 1.000
Y12 (q'aire) Grammar A 0.407 0.364 0.042 −0.060 0.149 1.000
Y12 (q'aire) Grammar C 0.477 0.490 −0.013 −0.108 0.080 1.000
Y12 (q'aire) Grammar E 0.116 0.145 −0.029 −0.056 −0.003 1.000
Y12 (q'aire) Parent-admin cognition A 0.186 0.244 −0.058 −0.157 0.042 1.000
Y12 (q'aire) Parent-admin cognition C 0.537 0.495 0.042 −0.046 0.132 1.000
Y12 (q'aire) Parent-admin cognition E 0.277 0.262 0.015 −0.013 0.045 1.000
Y12 (q'aire) Parent-report cognition A 0.295 0.311 −0.016 −0.146 0.111 1.000
Y12 (q'aire) Parent-report cognition C 0.571 0.549 0.022 −0.089 0.138 1.000
Y12 (q'aire) Parent-report cognition E 0.134 0.140 −0.006 −0.039 0.029 1.000
Y12 (q'aire) Conduct problems A 0.521 0.564 −0.043 −0.191 0.034 1.000
Y12 (q'aire) Conduct problems C 0.019 0.002 0.018 0.000 0.135 1.000
Y12 (q'aire) Conduct problems E 0.459 0.434 0.025 −0.034 0.087 1.000
Y12 (q'aire) Emotional problems A 0.565 0.589 −0.024 −0.168 0.067 1.000
Y12 (q'aire) Emotional problems C 0.032 0.016 0.016 −0.051 0.128 1.000
Y12 (q'aire) Emotional problems E 0.404 0.396 0.008 −0.045 0.062 1.000
Y12 (q'aire) Hyperactivity A 0.637 0.634 0.002 −0.052 0.056 1.000
Y12 (q'aire) Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y12 (q'aire) Hyperactivity E 0.363 0.366 −0.002 −0.056 0.052 1.000
Y12 (q'aire) Peer problems A 0.525 0.565 −0.040 −0.096 0.016 1.000
Y12 (q'aire) Peer problems C 0.000 0.000 0.000 0.000 0.000 1.000
Y12 (q'aire) Peer problems E 0.474 0.435 0.039 −0.016 0.094 1.000
Y12 (q'aire) Prosocial behavior A 0.389 0.438 −0.050 −0.166 0.064 1.000
Y12 (q'aire) Prosocial behavior C 0.388 0.329 0.059 −0.044 0.163 1.000
Y12 (q'aire) Prosocial behavior E 0.223 0.233 −0.009 −0.040 0.022 1.000
Y16 (q'aire) Vocabulary A 0.127 0.183 −0.057 −0.123 0.010 1.000
Y16 (q'aire) Vocabulary C 0.845 0.776 0.069 0.006 0.132 1.000
Y16 (q'aire) Vocabulary E 0.028 0.041 −0.013 −0.026 −0.001 1.000
Y16 (q'aire) Grammar A 0.200 0.365 −0.166 −0.293 −0.038 0.852
Y16 (q'aire) Grammar C 0.647 0.490 0.157 0.044 0.271 0.496
Y16 (q'aire) Grammar E 0.153 0.145 0.008 −0.025 0.043 1.000
Y16 (q'aire) Parent-admin cognition A 0.211 0.243 −0.032 −0.167 0.100 1.000
Y16 (q'aire) Parent-admin cognition C 0.506 0.495 0.012 −0.102 0.126 1.000
Y16 (q'aire) Parent-admin cognition E 0.282 0.262 0.020 −0.020 0.064 1.000
Y16 (q'aire) Parent-report cognition A 0.263 0.311 −0.048 −0.187 0.088 1.000
Y16 (q'aire) Parent-report cognition C 0.625 0.549 0.076 −0.043 0.201 1.000
Y16 (q'aire) Parent-report cognition E 0.112 0.140 −0.028 −0.067 0.005 1.000
Y16 (q'aire) Conduct problems A 0.468 0.564 −0.095 −0.289 0.010 1.000
Y16 (q'aire) Conduct problems C 0.030 0.002 0.028 0.000 0.187 1.000
Y16 (q'aire) Conduct problems E 0.502 0.435 0.067 −0.010 0.148 1.000
Y16 (q'aire) Emotional problems A 0.505 0.589 −0.084 −0.306 0.057 1.000
Y16 (q'aire) Emotional problems C 0.083 0.015 0.068 −0.020 0.249 1.000
Y16 (q'aire) Emotional problems E 0.412 0.396 0.016 −0.054 0.089 1.000
Y16 (q'aire) Hyperactivity A 0.607 0.634 −0.027 −0.096 0.038 1.000
Y16 (q'aire) Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y16 (q'aire) Hyperactivity E 0.393 0.366 0.027 −0.038 0.096 1.000
Y16 (q'aire) Peer problems A 0.488 0.565 −0.077 −0.157 −0.004 1.000
Y16 (q'aire) Peer problems C 0.001 0.000 0.001 0.000 0.000 1.000
Y16 (q'aire) Peer problems E 0.511 0.435 0.076 0.004 0.152 1.000
Y16 (q'aire) Prosocial behavior A 0.470 0.439 0.031 −0.123 0.187 1.000
Y16 (q'aire) Prosocial behavior C 0.298 0.328 −0.030 −0.173 0.108 1.000
Y16 (q'aire) Prosocial behavior E 0.232 0.233 −0.001 −0.042 0.041 1.000
Y18 Vocabulary A 0.146 0.183 −0.037 −0.097 0.019 1.000
Y18 Vocabulary C 0.823 0.776 0.047 −0.006 0.104 1.000
Y18 Vocabulary E 0.031 0.041 −0.010 −0.023 0.000 1.000
Y18 Grammar A 0.315 0.364 −0.049 −0.153 0.054 1.000
Y18 Grammar C 0.553 0.491 0.062 −0.031 0.156 1.000
Y18 Grammar E 0.133 0.145 −0.012 −0.038 0.012 1.000
Y18 Parent-admin cognition A 0.204 0.244 −0.040 −0.135 0.055 1.000
Y18 Parent-admin cognition C 0.521 0.494 0.027 −0.060 0.111 1.000
Y18 Parent-admin cognition E 0.275 0.261 0.013 −0.014 0.041 1.000
Y18 Parent-report cognition A 0.294 0.311 −0.017 −0.144 0.101 1.000
Y18 Parent-report cognition C 0.588 0.549 0.039 −0.062 0.152 1.000
Y18 Parent-report cognition E 0.117 0.140 −0.022 −0.056 0.009 1.000
Y18 Conduct problems A 0.536 0.564 −0.028 −0.186 0.049 1.000
Y18 Conduct problems C 0.025 0.001 0.024 0.000 0.159 1.000
Y18 Conduct problems E 0.439 0.434 0.005 −0.051 0.061 1.000
Y18 Emotional problems A 0.537 0.589 −0.052 −0.230 0.058 1.000
Y18 Emotional problems C 0.068 0.015 0.053 −0.014 0.199 1.000
Y18 Emotional problems E 0.395 0.396 0.000 −0.054 0.054 1.000
Y18 Hyperactivity A 0.641 0.635 0.006 −0.047 0.057 1.000
Y18 Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y18 Hyperactivity E 0.359 0.365 −0.006 −0.057 0.047 1.000
Y18 Peer problems A 0.581 0.565 0.016 −0.039 0.069 1.000
Y18 Peer problems C 0.001 0.000 0.001 0.000 0.000 1.000
Y18 Peer problems E 0.419 0.435 −0.016 −0.069 0.037 1.000
Y18 Prosocial behavior A 0.353 0.438 −0.086 −0.199 0.028 1.000
Y18 Prosocial behavior C 0.401 0.329 0.072 −0.031 0.173 1.000
Y18 Prosocial behavior E 0.246 0.233 0.014 −0.018 0.045 1.000
Y21 Vocabulary A 0.180 0.183 −0.003 −0.102 0.115 1.000
Y21 Vocabulary C 0.788 0.776 0.012 −0.103 0.107 1.000
Y21 Vocabulary E 0.032 0.041 −0.009 −0.024 0.003 1.000
Y21 Grammar A 0.300 0.364 −0.064 −0.233 0.109 1.000
Y21 Grammar C 0.572 0.491 0.081 −0.080 0.236 1.000
Y21 Grammar E 0.128 0.145 −0.018 −0.056 0.023 1.000
Y21 Parent-admin cognition A 0.306 0.243 0.062 −0.117 0.250 1.000
Y21 Parent-admin cognition C 0.436 0.495 −0.059 −0.229 0.094 1.000
Y21 Parent-admin cognition E 0.259 0.262 −0.003 −0.051 0.050 1.000
Y21 Parent-report cognition A 0.243 0.311 −0.068 −0.248 0.112 1.000
Y21 Parent-report cognition C 0.612 0.549 0.063 −0.099 0.223 1.000
Y21 Parent-report cognition E 0.145 0.140 0.005 −0.039 0.048 1.000
Y21 Conduct problems A 0.529 0.565 −0.035 −0.274 0.088 1.000
Y21 Conduct problems C 0.036 0.001 0.035 0.000 0.240 1.000
Y21 Conduct problems E 0.434 0.434 0.000 −0.090 0.096 1.000
Y21 Emotional problems A 0.488 0.590 −0.102 −0.387 0.062 1.000
Y21 Emotional problems C 0.086 0.015 0.070 −0.041 0.305 1.000
Y21 Emotional problems E 0.427 0.395 0.031 −0.056 0.122 1.000
Y21 Hyperactivity A 0.643 0.635 0.008 −0.077 0.089 1.000
Y21 Hyperactivity C 0.000 0.000 0.000 0.000 0.000 1.000
Y21 Hyperactivity E 0.357 0.365 −0.008 −0.089 0.077 1.000
Y21 Peer problems A 0.494 0.565 −0.071 −0.218 0.028 1.000
Y21 Peer problems C 0.009 0.000 0.009 0.000 0.125 1.000
Y21 Peer problems E 0.496 0.435 0.062 −0.028 0.154 1.000
Y21 Prosocial behavior A 0.412 0.439 −0.027 −0.222 0.171 1.000
Y21 Prosocial behavior C 0.356 0.329 0.028 −0.153 0.201 1.000
Y21 Prosocial behavior E 0.231 0.233 −0.001 −0.051 0.053 1.000
Y26 (q'aire) Vocabulary A 0.170 0.183 −0.013 −0.120 0.114 1.000
Y26 (q'aire) Vocabulary C 0.807 0.776 0.031 −0.095 0.136 1.000
Y26 (q'aire) Vocabulary E 0.023 0.041 −0.018 −0.032 −0.005 0.237
Y26 (q'aire) Grammar A 0.320 0.364 −0.043 −0.263 0.195 1.000
Y26 (q'aire) Grammar C 0.557 0.491 0.066 −0.157 0.267 1.000
Y26 (q'aire) Grammar E 0.122 0.145 −0.023 −0.070 0.029 1.000
Y26 (q'aire) Parent-admin cognition A 0.299 0.244 0.054 −0.171 0.288 1.000
Y26 (q'aire) Parent-admin cognition C 0.438 0.495 −0.057 −0.271 0.135 1.000
Y26 (q'aire) Parent-admin cognition E 0.264 0.261 0.002 −0.059 0.074 1.000
Y26 (q'aire) Parent-report cognition A 0.161 0.312 −0.151 −0.334 0.047 1.000
Y26 (q'aire) Parent-report cognition C 0.698 0.549 0.149 −0.031 0.313 1.000
Y26 (q'aire) Parent-report cognition E 0.141 0.139 0.002 −0.048 0.054 1.000
Y26 (q'aire) Conduct problems A 0.607 0.564 0.043 −0.199 0.173 1.000
Y26 (q'aire) Conduct problems C 0.029 0.001 0.027 −0.003 0.235 1.000
Y26 (q'aire) Conduct problems E 0.364 0.435 −0.071 −0.173 0.037 1.000
Y26 (q'aire) Emotional problems A 0.619 0.588 0.030 −0.258 0.206 1.000
Y26 (q'aire) Emotional problems C 0.063 0.016 0.048 −0.069 0.284 1.000
Y26 (q'aire) Emotional problems E 0.318 0.396 −0.078 −0.180 0.024 1.000
Y26 (q'aire) Hyperactivity A 0.735 0.634 0.101 0.003 0.192 1.000
Y26 (q'aire) Hyperactivity C 0.001 0.000 0.001 0.000 0.000 1.000
Y26 (q'aire) Hyperactivity E 0.264 0.366 −0.102 −0.192 −0.006 1.000
Y26 (q'aire) Peer problems A 0.552 0.565 −0.013 −0.304 0.137 1.000
Y26 (q'aire) Peer problems C 0.044 0.000 0.044 0.000 0.283 1.000
Y26 (q'aire) Peer problems E 0.404 0.435 −0.032 −0.142 0.087 1.000
Y26 (q'aire) Prosocial behavior A 0.561 0.438 0.123 −0.151 0.373 1.000
Y26 (q'aire) Prosocial behavior C 0.238 0.329 −0.092 −0.322 0.157 1.000
Y26 (q'aire) Prosocial behavior E 0.201 0.233 −0.032 −0.093 0.036 1.000
Y26 (web test) Vocabulary A 0.097 0.183 −0.087 −0.170 −0.001 1.000
Y26 (web test) Vocabulary C 0.886 0.776 0.111 0.029 0.190 0.832
Y26 (web test) Vocabulary E 0.017 0.041 −0.024 −0.039 −0.011 0.088
Y26 (web test) Grammar A 0.487 0.365 0.123 −0.262 0.511 1.000
Y26 (web test) Grammar C 0.390 0.490 −0.100 −0.472 0.266 1.000
Y26 (web test) Grammar E 0.123 0.145 −0.022 −0.084 0.046 1.000
Y26 (web test) Parent-admin cognition A 0.312 0.244 0.068 −0.260 0.476 1.000
Y26 (web test) Parent-admin cognition C 0.416 0.494 −0.078 −0.451 0.211 1.000
Y26 (web test) Parent-admin cognition E 0.272 0.262 0.010 −0.094 0.147 1.000
Y26 (web test) Parent-report cognition A 0.176 0.311 −0.135 −0.365 0.176 1.000
Y26 (web test) Parent-report cognition C 0.692 0.549 0.143 −0.154 0.356 1.000
Y26 (web test) Parent-report cognition E 0.132 0.140 −0.008 −0.070 0.063 1.000
Y26 (web test) Conduct problems A 0.746 0.564 0.181 −0.103 0.310 1.000
Y26 (web test) Conduct problems C 0.044 0.002 0.043 −0.003 0.311 1.000
Y26 (web test) Conduct problems E 0.210 0.434 −0.224 −0.311 −0.132 0.000
Y26 (web test) Emotional problems A 0.634 0.589 0.045 −0.330 0.263 1.000
Y26 (web test) Emotional problems C 0.072 0.015 0.056 −0.079 0.356 1.000
Y26 (web test) Emotional problems E 0.294 0.396 −0.102 −0.237 0.050 1.000
Y26 (web test) Hyperactivity A 0.752 0.634 0.118 −0.093 0.251 1.000
Y26 (web test) Hyperactivity C 0.012 0.000 0.012 0.000 0.175 1.000
Y26 (web test) Hyperactivity E 0.235 0.366 −0.130 −0.251 0.016 1.000
Y26 (web test) Peer problems A 0.410 0.565 −0.155 −0.564 0.126 1.000
Y26 (web test) Peer problems C 0.134 0.000 0.134 0.000 0.486 1.000
Y26 (web test) Peer problems E 0.456 0.435 0.021 −0.137 0.177 1.000
Y26 (web test) Prosocial behavior A 0.329 0.439 −0.110 −0.449 0.320 1.000
Y26 (web test) Prosocial behavior C 0.440 0.329 0.111 −0.284 0.416 1.000
Y26 (web test) Prosocial behavior E 0.231 0.233 −0.001 −0.108 0.126 1.000
1 P values are Bonferroni-Holm adjusted within each sex, parameter (A, C or E), and timepoint group

ACE Stacked Bar Plot

Code
bootstrap_summary_df_ace %>%
  # filter(dataset_label == "Y4") %>% 
  filter(par %in% c("a","c","e")) %>%
  filter(group != "Difference") %>%
  mutate(
    dataset_label = factor(dataset_label, levels = rq1y_twin_labels_clean_extrashort),
    name = factor(rq2y_labels_short[match(name, rq2y)], levels = rq2y_labels_short),
    group = ifelse(group == "Attritioned", "A", "O"),
    group = factor(group, levels = c("A", "O")),
    sex = str_to_title(sex),
    par = toupper(par)
  ) %>%
  ggplot(aes(x = group, y = y, fill = par)) +
  geom_col(position = "stack", alpha = 1) +
  facet_grid(dataset_label + sex ~ name, switch = "x") +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 0, hjust = .5, size = 8),
    strip.text = element_text(size = 8),
    strip.text.x = element_text(angle = 90, hjust = 1, vjust = .5, size = 8),
    strip.text.y = element_text(angle = 0, size = 10),
    strip.placement = "outside",
    panel.grid = element_blank(),
    plot.tag = element_text(hjust = 0, vjust = 0, size = 24, face = "bold"),
    plot.tag.position = "topleft"
  ) +
  labs(
    title = "Attritioned (A) vs Original (O) ACE Estimates",
    y     = "Proportion",
    x     = NULL,
    fill  = "Component"
  ) +
  scale_fill_manual(values = c("A" = "#d73027", "C" = "#fee08b", "E" = "#4575b4")) +
  coord_cartesian(ylim = c(0, 1))

Code
save_plot("2_rq2_ace_comparison", width = 7, height = 15, trim = TRUE)

# Create a looped version where we have plots for each timepoint

ace_plots = lapply(rq1y_twin_labels_clean_extrashort, function(timepoint) {

  bootstrap_summary_df_ace %>%
  filter(dataset_label == timepoint) %>%
  filter(par %in% c("a","c","e")) %>%
  filter(group != "Difference") %>%
  mutate(
    name = factor(rq2y_labels_short[match(name, rq2y)], levels = rq2y_labels_short),
    group = ifelse(group == "Attritioned", "A", "O"),
    group = factor(group, levels = c("A", "O")),
    sex = str_to_title(sex),
    par = toupper(par)
  ) %>%
  ggplot(aes(x = group, y = y, fill = par)) +
  geom_col(position = "stack", alpha = 1) +
  facet_grid(sex ~ name, switch = if(timepoint == "Y4") "both" else "x") +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 0, hjust = .5, size = 8),
    axis.text.y = if(timepoint != "Y4") element_blank(),
    strip.text = element_text(size = 8),
    strip.text.x = element_text(angle = 90, hjust = 1, vjust = .5, size = 8),
    strip.text.y = element_blank(),
    strip.text.y.left = if(timepoint == "Y4") element_text(angle = 0, size = 10) else element_blank(),
    strip.placement = "outside",
    panel.grid = element_blank()
  ) +
  labs(
    title = timepoint,
    y     = if(timepoint == "Y4") "Proportion" else NULL,
    x     = NULL,
    fill  = "Component"
  ) +
  scale_fill_manual(values = c("A" = "#d73027", "C" = "#fee08b", "E" = "#4575b4")) +
  coord_cartesian(ylim = c(0, 1))
})

names(ace_plots) = rq1y_twin_labels_clean_extrashort

# Arrange all plots vertically with shared legend
patchwork::wrap_plots(ace_plots, nrow = 1) +
  patchwork::plot_layout(guides = "collect") +
  patchwork::plot_annotation(
    title = "Attritioned (A) vs Original (O) ACE Estimates by Timepoint"
  )

Code
save_plot("2_rq2_ace_comparison_by_timepoint", width = 21, height = 9, trim = FALSE)

📊 View plot 1 📊 View plot 2

Supplementary Analyses

How predictive are our variables of later attrition?

Correlations

Code
sapply(rq2y, function(x)
  sapply(rq1y_twin1, function(y)
         cor(df[[x]],df[[y]], use = "pairwise.complete.obs")
  )) %>%
  `colnames<-`(rq2y_labels_short) %>%
  `rownames<-`(rq1y_twin_labels_clean_extrashort) %>%
  knitr::kable(digits = 3)
Maternal Education Vocabulary Grammar Parent-admin cognition Parent-report cognition Conduct problems Emotional problems Hyperactivity Peer problems Prosocial behavior
Y4 0.164 0.023 0.018 -0.030 0.032 -0.056 -0.013 -0.035 -0.043 -0.026
Y12 (web test) 0.181 0.026 0.032 -0.036 0.046 -0.045 0.010 -0.032 -0.046 -0.011
Y12 (q’aire) 0.176 0.022 0.025 -0.030 0.044 -0.055 0.008 -0.026 -0.054 -0.007
Y16 (q’aire) 0.179 0.012 0.014 -0.027 0.028 -0.065 0.002 -0.042 -0.050 -0.018
Y18 0.210 0.015 0.010 -0.054 0.028 -0.061 -0.002 -0.027 -0.062 -0.005
Y21 0.177 0.048 0.053 0.003 0.057 -0.054 0.002 -0.037 -0.054 0.002
Y26 (q’aire) 0.147 0.052 0.060 0.015 0.043 -0.037 0.004 -0.051 -0.047 0.003
Y26 (web test) 0.119 0.025 0.035 -0.004 0.030 -0.036 0.016 -0.033 -0.033 0.000

Regression Modelling

Code
models = list()

for (i in seq_along(rq1y_twin1)){
  cat(i, "/", length(rq1y_twin1),"\n")
  formula <- as.formula(paste(rq1y_twin1[i], "~", paste(rq2y, collapse = "+")))
  models[[i]] = glm(formula, data = df, family = binomial, na.action = "na.omit")
}
1 / 8 
2 / 8 
3 / 8 
4 / 8 
5 / 8 
6 / 8 
7 / 8 
8 / 8 
Code
# glm_model_comparison(models[[1]])
# 
# lapply(models, function(x) performance::r2(x))
# lapply(models, function(x) calc_auc(x))
# lapply(models, function(x) summary(x))



# calc_auc(models[[1]])

Plot of AUC and R2 for each timepoint

Code
# Extract AUC and pseudo R2 for each model
model_metrics = data.frame(
  outcome = sapply(models, function(x) as.character(x$formula)[2]),
  AUC = sapply(models, calc_auc),
  R2 = sapply(models, function(x) performance::r2(x)$R2)
) %>%
  mutate(outcome = rq1y_twin_labels_clean[match(.$outcome, rq1y_twin1)])

# First, order the outcomes chronologically by extracting year numbers
model_metrics_ordered = model_metrics %>%
  mutate(
    year_num = as.numeric(str_extract(outcome, "\\d+")),
    outcome = fct_reorder(outcome, year_num)
  )

plot_data = model_metrics_ordered %>%
  pivot_longer(cols = c(AUC, R2)) %>%
  mutate(
    # Format labels
    label_text = ifelse(name == "R2", 
                       paste0(sprintf("%.1f", value * 100), "%"),
                       sprintf("%.3f", value)),
    label_text = ifelse(name == "AUC", 
                       gbtoolbox::apa_num(value, n_decimal_places = 3),
                       label_text),
    # Adjust bar start position for AUC (start from 0.5 instead of 0)
    value_start = ifelse(name == "AUC", 0.5, 0),
    value_width = value - value_start
  )

plot_data %>%
  ggplot(aes(y = outcome)) +
  geom_rect(aes(xmin = value_start, xmax = value, ymin = as.numeric(outcome) - 0.4, ymax = as.numeric(outcome) + 0.4), 
            fill = "steelblue", alpha = 0.7) + 
  geom_text(aes(x = value, label = label_text), hjust = -0.1, size = 3) +
  facet_wrap(~name, scales = "free", 
             labeller = labeller(name = c("AUC" = "AUC", "R2" = "Tjur's R²"))) +
  scale_x_continuous(
    labels = function(x) {
      # Check if we're in the R2 facet by looking at the range
      if (max(x, na.rm = TRUE) < 0.2) {  # R2 values are typically small
        paste0(round(x * 100, 1), "%")
      } else {
        sprintf("%.2f", x)
      }
    },
    expand = expansion(mult = c(0, 0.15)),
    limits = function(x) {
      # Set minimum limit to 0.5 for AUC facet (values > 0.2)
      if (max(x, na.rm = TRUE) > 0.2) {
        c(0.5, max(x, na.rm = TRUE) * 1.05)
      } else {
        c(0, max(x, na.rm = TRUE) * 1.05)
      }
    }
  ) +
  labs(
    title = "Prediction Accuracy Across Study Timepoints",
    x = "Value",
    y = "Study Timepoint"
  ) +
  theme_minimal() +
  theme(
    strip.text = element_text(face = "bold"),
    plot.title = element_text(hjust = 0.5)
  )

Code
save_plot("2_prediction_accuracy", width = 9, height = 6)

Full model results

Code
# Extract all coefficients and combine
models_results = do.call(rbind, lapply(1:length(models), function(i) {
  coefs = tidy(models[[i]])
  coefs$outcome = as.character(models[[i]]$formula)[2]
  return(coefs)
}))

models_results %>% 
  select(outcome, everything()) %>%
  mutate(
    outcome = var_to_label(outcome) %>% str_remove("data.*"),
    term = df_labels[match(.$term,df_colnames)],
    term   = ifelse(is.na(term), "Intercept", term),
    p_star = as.character(symnum(p.value, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c("***", "**", "*", ".", " ")))
  ) %>% 
  knitr::kable(., digits = 3)
outcome term estimate std.error statistic p.value p_star
Twin booklet NULL 0.672 0.158 4.265 0.000 ***
Twin booklet Maternal Education (formatted as numeric variable) 0.138 0.012 11.189 0.000 ***
Twin booklet Vocabulary total score (2 Year), 0-100 0.003 0.001 2.449 0.014 *
Twin booklet Grammar composite score (2 Year), 0-2 -0.041 0.039 -1.048 0.294
Twin booklet Parent-administered Parca mean score (2 Year), standardised -0.081 0.026 -3.187 0.001 **
Twin booklet Parent-reported Parca total score (2 Year), 0-26 0.016 0.008 2.089 0.037 *
Twin booklet Conduct SDQ-comparable Behar subscale (2 Year), 0-8 -0.073 0.017 -4.248 0.000 ***
Twin booklet Emotion SDQ-comparable Behar subscale (2 Year), 0-4 -0.003 0.027 -0.124 0.901
Twin booklet Hyperactivity SDQ-comparable Behar subscale (2 Year), 0-6 -0.009 0.015 -0.626 0.531
Twin booklet Peer SDQ-comparable Behar subscale (2 Year), 0-6 -0.047 0.024 -1.961 0.050 *
Twin booklet Prosocial SDQ-comparable Behar subscale (2 Year), 0-10 -0.040 0.011 -3.648 0.000 ***
Twin web NULL -0.621 0.139 -4.477 0.000 ***
Twin web Maternal Education (formatted as numeric variable) 0.146 0.010 14.224 0.000 ***
Twin web Vocabulary total score (2 Year), 0-100 0.001 0.001 0.989 0.323
Twin web Grammar composite score (2 Year), 0-2 0.015 0.035 0.426 0.670
Twin web Parent-administered Parca mean score (2 Year), standardised -0.100 0.022 -4.440 0.000 ***
Twin web Parent-reported Parca total score (2 Year), 0-26 0.021 0.007 2.949 0.003 **
Twin web Conduct SDQ-comparable Behar subscale (2 Year), 0-8 -0.036 0.015 -2.345 0.019 *
Twin web Emotion SDQ-comparable Behar subscale (2 Year), 0-4 0.054 0.024 2.195 0.028 *
Twin web Hyperactivity SDQ-comparable Behar subscale (2 Year), 0-6 -0.007 0.013 -0.558 0.577
Twin web Peer SDQ-comparable Behar subscale (2 Year), 0-6 -0.061 0.021 -2.855 0.004 **
Twin web Prosocial SDQ-comparable Behar subscale (2 Year), 0-10 -0.020 0.010 -2.102 0.036 *
Child questionnaire NULL -0.416 0.139 -2.997 0.003 **
Child questionnaire Maternal Education (formatted as numeric variable) 0.128 0.010 12.459 0.000 ***
Child questionnaire Vocabulary total score (2 Year), 0-100 0.002 0.001 1.431 0.153
Child questionnaire Grammar composite score (2 Year), 0-2 0.008 0.035 0.243 0.808
Child questionnaire Parent-administered Parca mean score (2 Year), standardised -0.079 0.022 -3.530 0.000 ***
Child questionnaire Parent-reported Parca total score (2 Year), 0-26 0.019 0.007 2.686 0.007 **
Child questionnaire Conduct SDQ-comparable Behar subscale (2 Year), 0-8 -0.064 0.015 -4.182 0.000 ***
Child questionnaire Emotion SDQ-comparable Behar subscale (2 Year), 0-4 0.056 0.024 2.311 0.021 *
Child questionnaire Hyperactivity SDQ-comparable Behar subscale (2 Year), 0-6 0.005 0.013 0.385 0.700
Child questionnaire Peer SDQ-comparable Behar subscale (2 Year), 0-6 -0.078 0.021 -3.672 0.000 ***
Child questionnaire Prosocial SDQ-comparable Behar subscale (2 Year), 0-10 -0.019 0.010 -1.954 0.051 .
Child behaviour booklet NULL -0.581 0.140 -4.161 0.000 ***
Child behaviour booklet Maternal Education (formatted as numeric variable) 0.152 0.010 14.991 0.000 ***
Child behaviour booklet Vocabulary total score (2 Year), 0-100 0.001 0.001 1.074 0.283
Child behaviour booklet Grammar composite score (2 Year), 0-2 -0.018 0.035 -0.512 0.609
Child behaviour booklet Parent-administered Parca mean score (2 Year), standardised -0.053 0.023 -2.336 0.019 *
Child behaviour booklet Parent-reported Parca total score (2 Year), 0-26 0.010 0.007 1.364 0.173
Child behaviour booklet Conduct SDQ-comparable Behar subscale (2 Year), 0-8 -0.065 0.016 -4.156 0.000 ***
Child behaviour booklet Emotion SDQ-comparable Behar subscale (2 Year), 0-4 0.043 0.025 1.737 0.082 .
Child behaviour booklet Hyperactivity SDQ-comparable Behar subscale (2 Year), 0-6 -0.017 0.013 -1.335 0.182
Child behaviour booklet Peer SDQ-comparable Behar subscale (2 Year), 0-6 -0.074 0.021 -3.444 0.001 ***
Child behaviour booklet Prosocial SDQ-comparable Behar subscale (2 Year), 0-10 -0.028 0.010 -2.850 0.004 **
Twin questionnaire NULL -0.442 0.141 -3.127 0.002 **
Twin questionnaire Maternal Education (formatted as numeric variable) 0.192 0.011 17.757 0.000 ***
Twin questionnaire Vocabulary total score (2 Year), 0-100 0.003 0.001 2.455 0.014 *
Twin questionnaire Grammar composite score (2 Year), 0-2 -0.071 0.035 -2.011 0.044 *
Twin questionnaire Parent-administered Parca mean score (2 Year), standardised -0.133 0.023 -5.783 0.000 ***
Twin questionnaire Parent-reported Parca total score (2 Year), 0-26 0.011 0.007 1.561 0.118
Twin questionnaire Conduct SDQ-comparable Behar subscale (2 Year), 0-8 -0.050 0.016 -3.227 0.001 **
Twin questionnaire Emotion SDQ-comparable Behar subscale (2 Year), 0-4 0.013 0.025 0.520 0.603
Twin questionnaire Hyperactivity SDQ-comparable Behar subscale (2 Year), 0-6 0.008 0.013 0.642 0.521
Twin questionnaire Peer SDQ-comparable Behar subscale (2 Year), 0-6 -0.088 0.022 -4.091 0.000 ***
Twin questionnaire Prosocial SDQ-comparable Behar subscale (2 Year), 0-10 -0.002 0.010 -0.188 0.851
TEDS21 phase 1 twin qnr NULL -0.942 0.140 -6.712 0.000 ***
TEDS21 phase 1 twin qnr Maternal Education (formatted as numeric variable) 0.141 0.010 14.008 0.000 ***
TEDS21 phase 1 twin qnr Vocabulary total score (2 Year), 0-100 0.001 0.001 1.303 0.193
TEDS21 phase 1 twin qnr Grammar composite score (2 Year), 0-2 0.056 0.035 1.600 0.110
TEDS21 phase 1 twin qnr Parent-administered Parca mean score (2 Year), standardised -0.013 0.023 -0.569 0.569
TEDS21 phase 1 twin qnr Parent-reported Parca total score (2 Year), 0-26 0.016 0.007 2.227 0.026 *
TEDS21 phase 1 twin qnr Conduct SDQ-comparable Behar subscale (2 Year), 0-8 -0.056 0.016 -3.627 0.000 ***
TEDS21 phase 1 twin qnr Emotion SDQ-comparable Behar subscale (2 Year), 0-4 0.034 0.025 1.399 0.162
TEDS21 phase 1 twin qnr Hyperactivity SDQ-comparable Behar subscale (2 Year), 0-6 -0.001 0.013 -0.066 0.947
TEDS21 phase 1 twin qnr Peer SDQ-comparable Behar subscale (2 Year), 0-6 -0.068 0.022 -3.161 0.002 **
TEDS21 phase 1 twin qnr Prosocial SDQ-comparable Behar subscale (2 Year), 0-10 -0.016 0.010 -1.676 0.094 .
TEDS26 twin MHQ NULL -0.861 0.143 -6.035 0.000 ***
TEDS26 twin MHQ Maternal Education (formatted as numeric variable) 0.107 0.010 10.562 0.000 ***
TEDS26 twin MHQ Vocabulary total score (2 Year), 0-100 0.002 0.001 1.408 0.159
TEDS26 twin MHQ Grammar composite score (2 Year), 0-2 0.092 0.035 2.593 0.010 **
TEDS26 twin MHQ Parent-administered Parca mean score (2 Year), standardised 0.016 0.023 0.700 0.484
TEDS26 twin MHQ Parent-reported Parca total score (2 Year), 0-26 0.003 0.007 0.478 0.633
TEDS26 twin MHQ Conduct SDQ-comparable Behar subscale (2 Year), 0-8 -0.020 0.016 -1.237 0.216
TEDS26 twin MHQ Emotion SDQ-comparable Behar subscale (2 Year), 0-4 0.038 0.025 1.531 0.126
TEDS26 twin MHQ Hyperactivity SDQ-comparable Behar subscale (2 Year), 0-6 -0.035 0.013 -2.604 0.009 **
TEDS26 twin MHQ Peer SDQ-comparable Behar subscale (2 Year), 0-6 -0.070 0.022 -3.179 0.001 **
TEDS26 twin MHQ Prosocial SDQ-comparable Behar subscale (2 Year), 0-10 -0.017 0.010 -1.679 0.093 .
CATSLife twin web study: NULL -1.913 0.178 -10.738 0.000 ***
CATSLife twin web study: Maternal Education (formatted as numeric variable) 0.116 0.012 9.596 0.000 ***
CATSLife twin web study: Vocabulary total score (2 Year), 0-100 0.000 0.001 0.257 0.797
CATSLife twin web study: Grammar composite score (2 Year), 0-2 0.083 0.044 1.891 0.059 .
CATSLife twin web study: Parent-administered Parca mean score (2 Year), standardised -0.029 0.029 -0.995 0.320
CATSLife twin web study: Parent-reported Parca total score (2 Year), 0-26 0.006 0.009 0.717 0.473
CATSLife twin web study: Conduct SDQ-comparable Behar subscale (2 Year), 0-8 -0.044 0.020 -2.200 0.028 *
CATSLife twin web study: Emotion SDQ-comparable Behar subscale (2 Year), 0-4 0.072 0.031 2.334 0.020 *
CATSLife twin web study: Hyperactivity SDQ-comparable Behar subscale (2 Year), 0-6 -0.024 0.017 -1.450 0.147
CATSLife twin web study: Peer SDQ-comparable Behar subscale (2 Year), 0-6 -0.053 0.027 -1.931 0.053 .
CATSLife twin web study: Prosocial SDQ-comparable Behar subscale (2 Year), 0-10 -0.012 0.012 -0.988 0.323

Variable Importance Calculations

Note: Variable importance is calculated by measuring the change in AUC when each variable is removed from the model.

Code
glm_model_comparison_results = lapply(models, glm_model_comparison)

glm_model_comparison_results_df = do.call("rbind.data.frame", glm_model_comparison_results)

# glm_model_comparison_results_df$LRT_p_star = glm_model_comparison_results_df$LRT_p %>%
#   symnum(., cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c("***", "**", "*", ".", " "))

# Adjust p-values and add star

glm_model_comparison_results_df = glm_model_comparison_results_df %>% 
  filter(Variables_Dropped!="None") %>%
  group_by(outcome) %>%
  mutate(LRT_p = stats::p.adjust(LRT_p, method = "holm")) %>% 
  ungroup() %>%
  mutate(
    LRT_p_star = as.character(symnum(LRT_p, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c("***", "**", "*", ".", " ")))
  )

variable_importance_order = glm_model_comparison_results_df %>%
  group_by(Variables_full) %>%
  summarise(mean_score = mean(LRT_p)) %>%
  arrange(mean_score) %>%
  pull(Variables_full)
glm_model_comparison_results_df = glm_model_comparison_results_df %>%
  mutate(
    Variables_full = factor(Variables_full, levels = variable_importance_order)
  )

# Plotting code
glm_model_comparison_results_df %>%
  mutate(
    Variables_full = rq2y_labels_short[match(.$Variables_full, rq2y_labels)],
    outcome_labeled = rq1y_twin_labels_clean_extrashort[match(.$outcome, rq1y_twin1)],
    criterion       = Delta_AUC,
    sig_level = case_when(
      LRT_p < 0.001 ~ "p < 0.001",
      LRT_p < 0.01 ~ "p < 0.01", 
      LRT_p < 0.05 ~ "p < 0.05",
      LRT_p < 0.1 ~ "p < 0.1",
      TRUE ~ "Not significant"
    ),
    sig_level = factor(sig_level, levels = c("p < 0.001", "p < 0.01", "p < 0.05", "p < 0.1", "Not significant"))
  ) %>%
  ggplot(aes(y = Variables_full, x = criterion)) + 
  geom_col(aes(fill = sig_level), alpha = 0.8) + 
  geom_text(aes(label = gsub("0\\.", ".", sprintf("%.3f", criterion))),  # Remove ALL 0. patterns
            size = 2.5, fontface = "bold", color = "black") +
  facet_wrap(~outcome_labeled, scales = "fixed", ncol = 6) +
  scale_x_continuous(labels = function(x) gsub("0\\.", ".", sprintf("%.3f", x))) +  # Remove ALL 0. patterns
  scale_fill_manual(
    values = c("p < 0.001" = "#d73027", "p < 0.01" = "#fc8d59", 
               "p < 0.05" = "#fee08b", "p < 0.1" = "#e0f3f8", 
               "Not significant" = "#d9d9d9"),
    name = "Significance\n(Holm-adjusted)"
  ) +
  labs(
    x = "Change in AUC (when variable removed)",
    y = NULL,
    title = "Variable Importance by AUC Change",
    subtitle = "Colors show Holm-adjusted significance levels"
  ) +
  theme_minimal() +
  theme(
    axis.text.y = element_text(size = 7),
    axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
    strip.text = element_text(size = 9, face = "bold"),
    legend.position = "bottom"
  )

Code
save_plot("2_rq2_variable_importance", width = 14, height = 7)

Comparison of maternal education scores

Code
df %>% 
  # group_by(zcdata1) %>%
  summarise(
    mean = mean(amohqualn, na.rm = TRUE),
    var  = stats::var(amohqualn1, na.rm = TRUE),
    sd  = stats::sd(amohqualn1, na.rm = TRUE)
    )
Code
df %>% 
  group_by(zcdata1) %>%
  summarise(
    mean = mean(amohqualn, na.rm = TRUE),
    var  = stats::var(amohqualn1, na.rm = TRUE),
    sd   = stats::sd(amohqualn1, na.rm = TRUE)
    
    )